Change Audio Device in Unity

With the Unity engines native audio system, when a new audio device is plugged into the computer, the audio starts coming out of the new device. What we’ve been experiencing, however, is that the FMOD plugin for Unity doesn’t do the same thing. The audio from FMOD will keep going through the original audio device if a new one is plugged into the system.

What is the best way to encourage the FMOD Unity plugin to update its chosen output device as new devices are plugged and unplugged from a computer?

Our policy currently is to not jump audio from one device to another because it is plugged in, that’s for the user to decide.
System::setDriver is the function used to switch devices on the fly.

FMOD’s auto handling behaviour is:

  1. if no device is installed at startup, and it is plugged in later, FMOD will jump to it.
  2. if all devices are unplugged during playback, it will switch to FMOD_OUTPUT_NOSOUND
  3. if a device is plugged in after step #2 happens, FMOD jumps to it.
  4. If a device is plugged in after step #3 happens that was the original device when step #2 happened, FMOD will jump to it.

Thank you very much! That’s very informative. One remaining question I’d like to ask, if you don’t mind. Is there any sort of callback we can hook into to know if the number of devices has changed? Or do we just need to look at the results of functions like getNumDrivers & getDriverInfo.

There is! Only problem is if you use it, it disables the automatic handling because it thinks you want to determine what happens. (maybe you do!) It is FMOD_SYSTEM_CALLBACK_DEVICELISTCHANGED

Otherwise you could just use getNumDrivers, it is basically what happens inside FMOD to determine if the device list has changed.

Thanks for the followup. With all the information provided, we were able to sort out our own behavior regarding this situation that suits our needs and design desires.

“What is the best way to encourage the FMOD Unity plugin to update its
chosen output device as new devices are plugged and unplugged from a

Just to directly respond to this, FMOD_SYSTEM_CALLBACK_DEVICELISTCHANGED lets you change the jump behaviour, so that you can get what you want. It takes the switching away from fmod and lets you define what happens.

One thing to add is, is unity’s method better than ours? Do you want it to jump to a new device? How does the user stop it jumping if you use that technique. Maybe the new device was just plugged in randomly and didnt want to be switched to. Letting the user select a device in the UI always helps.

This answer appears to be outdated in the current version of FMOD. The text “FMOD_SYSTEM_CALLBACK_DEVICELISTCHANGED” now only exists in a comment in fmod.cs; “DEVICELISTCHANGED” does appear in the code, however, and I assume the code was refactored and the comment simply missed. Hopefully this helps anyone else looking for this functionality.

I’m trying to figure this out, but I’m not sure how to affect these settings?
I’ve found a mention of DEVICELISTCHANGED in fmod.cs, but it doesn’t seem like I should be editing it there. What C# commands should I use to change these settings? I couldn’t find it in the documentation.

As to @brett’s question

is unity’s method better than ours?

I think for the majority of users, the most common usecase is plug in/out headphones (or enable/disable bluetooth headphones), so I’d want hopping to new device to be the default, and let users hard-set their audio device in the settings if they have a more complicated setup.

This topic is 5 years old. Please refer to covers this issue well enough.

To answer the quoted question, yes, Unity’s method is better than FMOD. I’m also trying to figure this out, because the device output just isn’t matching how Unity does it. I figured the Unity Integration would default to exactly how Unity handles device output management. That way audio output never gets out of sync.

But at least with Unity 2019, it is in fact out of sync with our project.

you are quoting a 5 year old quote. Please read the documentation linked

If the device that is being played on is removed (such as a USB audio device), it will automatically jump to the device considered next most important (ie on Windows, it would be the new ‘default’ device).

If a device is inserted, then removed, it will jump to the device it was originally playing on.

The programmer can override the sound card detection behavior, with a custom callback. This is the FMOD_SYSTEM_CALLBACK_DEVICELISTCHANGED callback