I’ve been trying to include basic mute functionality in my Unity project without success. I can’t see anything in the FMOD_StudioSystem class that supports this natively, and when reusing the code found in OnApplicationPause:
FMOD.System sys;
ERRCHECK(system.getLowLevelSystem(out sys));
FMOD.Studio.UnityUtil.Log("Pause state changed to: " + pauseStatus);
if (pauseStatus)
{
ERRCHECK(sys.mixerSuspend());
}
else
{
ERRCHECK(sys.mixerResume());
}
in a button trigger event, the audio does not mute despite the fact that sys.mixerSuspend() is being called.
Is there an easier way to do this that I’m ignoring?
I’m guessing your running this on a PC/Mac. Mixer suspend is designed for phones to save CPU and thus battery life when your application is not in the foreground. It’s not what you want to use when your application is running but doesn’t want sound.
Try muting the master bus:
FMOD.Studio.GUID masterId;
ERRCHECK(system.lookupID("bus:/", out masterId));
FMOD.Studio.MixerStrip master;
ERRCHECK(system.getMixerStrip(masterId, FMOD.Studio.LOADING_MODE.BEGIN_NOW, out master));
ERRCHECK(master.setMute(true));
Or create a snapshot that reduces the volume of the master bus to -inf and start and stop that.
Sorry I didn’t mention it in the OP, but this is actually for mobile devices (both Android and iOS).
I’ve tried implementing your solution, but the code:
private FMOD_StudioSystem studio;
private FMOD.System lowLevelSystem;
private FMOD.GUID masterId;
private FMOD.Studio.MixerStrip masterMixer;
public void Awake()
{
studio = FMOD_StudioSystem.instance;
studio.System.getLowLevelSystem(out lowLevelSystem);
CheckForErrors(studio.System.lookupID("bus:/", out masterId));
CheckForErrors(studio.System.getMixerStrip(masterId, FMOD.Studio.LOADING_MODE.BEGIN_NOW, out masterMixer));
Debug.Log("AudioEngine Awoken()");
}
raises an error saying the the “bus:/” event is not found (FMOD_RESULT - ERR_EVENT_NOTFOUND), despite it being listed exactly as you mentioned it in the GUIDs.txt in the FMOD Build folder…
Should I still be trying to utilize this method is the intended platform is mobile?
How would you implement a volume-reducing snapshot instead?
string masterBusString = "Bus:/YOUR_BUS_NAME/";
FMOD.Studio.Bus masterBus;
private void Start(){
//Initialize the bus.
masterBus = FMODUnity.RuntimeManager.GetBus(masterBusString);
MuteUnmuteBus(true);
}
//Call on this Method from here or a different script (eg. from a button with a trigger-script, which calls on the mute/unmute-method)
//"setMuted" should be TRUE for muting the bus, FALSE for unMuting it.
public void MuteUnmuteBus(bool setMuted){
masterBus.setMute(setMuted);
}