I've just installed Unity 3D because I wanted to make a simple game. There is one problem with the NAudio library though.
This is my code:
var enumerator = new MMDeviceEnumerator();
if (enumerator.HasDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia)) //<--- crashes here
{
//...
}
This is literally all Unity says when trying to launch the game:
NullReferenceException: Object reference not set to an instance of an object NAudio.CoreAudioApi.MMDeviceEnumerator.HasDefaultAudioEndpoint (DataFlow dataFlow, Role role)
I don't understand why it throws this kind of error here. Could it be that the library might not be compatible with this version of net framework (version 3.5)?
EDIT: the variable enumerator can't be null, so stop flagging this post as a duplicate of 'What is a NullReferenceException, and how do I fix it?'
I've also tried using this libary: https://code.google.com/archive/p/naudio-with-unity3d/downloads
That library only doesn't contain the HasDefaultAudioEndpoint()
function, so I just tried getting the audio endpoint directly by calling GetDefaultAudioEndpoint()
but it still threw that same error on that line.