FMOD Bus.SetMute() does not work as I want。What is the correct process?

I want to init FMOD bus after game login. And a param is needed to init the bus.The Code like this:
// BoyVoice
if (FMODUnity.RuntimeManager.HasBus(“bus:/boy”))
{
bool res = false;
var bus = FMODUnity.RuntimeManager.GetBus(“bus:/boy”);
bus.stopAllEvents(STOP_MODE.IMMEDIATE);
var result = bus.setMute(isGirlVoice);
var resultOne = bus.getMute(out res);
Debug.Log("[BoyVoiceMute]:" + result.ToString() + “|” + res + “|” + resultOne);
}
// GirlVoice
if (FMODUnity.RuntimeManager.HasBus(“bus:/girl”))
{
bool res = false;
var newBus = FMODUnity.RuntimeManager.GetBus(“bus:/girl”);
newBus.stopAllEvents(STOP_MODE.IMMEDIATE);
var result = newBus.setMute(!isGirlVoice);
var resultOne = newBus.getMute(out res);
UnityEngine.Debug.Log("[GirlVoiceMute]:" + result.ToString() + “|” + res + “|” + resultOne);
}
And a switch button is provided to change setting.
The first time this code running well after game login, eg: if I chose Girl Voice ,the log like this:
[BoyVoiceMute]:OK|true|OK
[GirlVoiceMute]:OK|false|OK
But if switch the button for several times, one bus cant be open anymore. Log like this:
[BoyVoiceMute]:OK|true|OK
[GirlVoiceMute]:OK|true|OK
both the bus is muted, the boyVoice bus cant be open, and I dont know why?
Any help will be Appreciate!

I’d look into channel-group locking: https://fmod.com/resources/documentation-api?version=1.10&page=content/generated/FMOD_Studio_Bus_LockChannelGroup.html

You can call bus.lockChannelGroup followed by RuntimeManager.StudioSystem.flushCommands to force the channel group to exist.

As you’re stopping all events, the bus/channel-group will be destroyed. Therefore, setting or getting values on the bus would probably result in weird behaviour.

However, I’d probably suggest something like this that doesn’t involve forcing the creation of the bus:
(pseudo code)

var bus = GetBus("boy or girl");
FMOD.RESULT channelGroupState = bus.getChannelGroup();
if (channelGroupState == RESULT.OK)
{
bus.setMute();
bus.stopAllEvents();
}

The ‘getChannelGroup’ command returns FMOD_ERR_STUDIO_NOT_LOADED if the channel group is destroyed. https://fmod.com/resources/documentation-api?version=1.10&page=content/generated/FMOD_Studio_Bus_GetChannelGroup.html

Another alternative would be to not stop all the events, meaning the bus persists and there’s no reason to check the channel group’s state or force the creation of it.

Hope this gives you some options!

2 Likes