Muting master bus fails in editor

So it’s clear why this happens, but it seems very silly to me. There is a flag in RuntimeManager that duplicates the muted state of the master bus, and forces it back on or off in Update:

        private void Update()
        {
            if (studioSystem.isValid())
            {
                // ...

                #if UNITY_EDITOR
                ApplyMuteState();

This means my own bus mute toggle gets overriden in the editor:

    public static void SetMute(string bus, bool isMuted) {
      AssertOk(RuntimeManager.GetBus(bus).setMute(isMuted));
    }

This is confusing to use. For all other buses I can use GetBus(busName).setMute(true). Why have one in particular that has its own special handling?

Hi,

The ApplyMuteState() is used if the Mute Audio option is selected in the Editor:
image

If you want to mute the MasterBus you can use FMODUnity.RuntimeManager.MuteAllEvents(true/false) (Unity Integration | Scripting API Reference).

Hope this helps!

Right. I understand the problem you’re solving now. You want to use the same bus’s muted state to handle two ways of toggling mute. One is the “Mute Audio” button, and the other is “SetAllEventsMuted”. The problem I’ve run into is that this is inconsistent with how I expected to be able to mute a bus (Bus.setMute).

For context I wrote this code that looks like it should work (and does work in build):

    static class Bus {
      public static readonly string Master = "bus:/";
      public static readonly string Music = "bus:/Music";
      public static readonly string Sfx = "bus:/Sfx";
    }

    void Start() {
      void Init(
        string bus,
        FloatVariable volume,
        BoolVariable muted
      ) {
        volume.Value = FmodUtility.GetVolume(bus);
        muted.Value = FmodUtility.GetMute(bus);
        volume.Change.Register(value => FmodUtility.SetVolume(bus, value));
        muted.Change.Register(value => FmodUtility.SetMute(bus, value));
      }
      Init(Bus.Master, _masterVolume, _muteMaster);
      Init(Bus.Music, _musicVolume, _muteMusic);
      Init(Bus.Sfx, _sfxVolume, _muteSfx);
    }

It seems like this would be sufficient to respect the editor mute button:

void MuteAllEvents(bool muted) {
  _masterBus.SetMute(muted);
}

private static void ApplyMuteState()
{
    #if UNITY_EDITOR
    if (HaveMasterBanksLoaded)
    {
        if (
          StudioSystem.getBus("bus:/", out var masterBus) == FMOD.RESULT.OK &&
          masterBus.getMute(out var isMuted) == FMOD.RESULT.OK &&
          isMuted != EditorUtility.audioMasterMute
        )
        {
          masterBus.setMute(EditorUtility.audioMasterMute);
        }
    }
    #endif
}

I guess the downside would be that unmuting the game would override previous calls to masterBus.setMute.

Anyway, it’s a small thing, I just thought I’d mention it because I ended up having to dig into the code to work out why setMute wasn’t applying changes. It’s fine so long as we remember that our in-game mute button doesn’t work in editor.

Thanks for sharing the code, I will make a note of it and if there is sufficient need for the change I can pass it on to our development team to look into further.

1 Like