# Muting master bus fails in editor

**URL:** <https://qa.fmod.com/t/muting-master-bus-fails-in-editor/19877>\
**Category:** Unity\
**Created:** [February 16, 2023, 10:33am UTC](https://qa.fmod.com/t/muting-master-bus-fails-in-editor/19877 "2023-02-16T10:33:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rhys\_vdw](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/rhys_vdw/32/2454_2.png) [@rhys\_vdw](https://qa.fmod.com/u/rhys_vdw)\
**Post date:** [February 16, 2023, 10:33am UTC](https://qa.fmod.com/t/muting-master-bus-fails-in-editor/19877/1 "2023-02-16T10:33:34Z")

</div>

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:

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

                #if UNITY_EDITOR
                ApplyMuteState();

```

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

```auto
    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?

---

<div class="post-metadata">

**Author:** ![Connor\_FMOD](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/connor_fmod/32/3685_2.png) [@Connor\_FMOD](https://qa.fmod.com/u/Connor_FMOD)\
**Post date:** [February 20, 2023, 3:43am UTC](https://qa.fmod.com/t/muting-master-bus-fails-in-editor/19877/2 "2023-02-20T03:43:53Z")

</div>

Hi,

The `ApplyMuteState()` is used if the `Mute Audio` option is selected in the Editor:  
 ![image](https://canada1.discourse-cdn.com/flex036/uploads/fmod/original/2X/5/5e0e410dd5ecfd4fc57f1f156f2aa1f4199d67d1.png)

If you want to mute the `MasterBus` you can use `FMODUnity.RuntimeManager.MuteAllEvents(true/false)` ([Unity Integration | Scripting API Reference](https://fmod.com/docs/2.02/unity/api-runtimemanager.html#muteallevents)).

Hope this helps!

---

<div class="post-metadata">

**Author:** ![rhys\_vdw](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/rhys_vdw/32/2454_2.png) [@rhys\_vdw](https://qa.fmod.com/u/rhys_vdw)\
**Post date:** [February 20, 2023, 6:21am UTC](https://qa.fmod.com/t/muting-master-bus-fails-in-editor/19877/3 "2023-02-20T06:21:11Z")

</div>

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):

```plaintext
    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:

```plaintext
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.

---

<div class="post-metadata">

**Author:** ![Connor\_FMOD](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/connor_fmod/32/3685_2.png) [@Connor\_FMOD](https://qa.fmod.com/u/Connor_FMOD)\
**Post date:** [February 20, 2023, 6:33am UTC](https://qa.fmod.com/t/muting-master-bus-fails-in-editor/19877/4 "2023-02-20T06:33:15Z")

</div>

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.
