How do you mute a AudioMixerGroup from code?

I typed the following code expecting to see mute, solo and bypassEffects methods or properties, and I see…NONE of it from Intellisense. Where the heck is it hiding? How do you do that?

public AudioMixerGroup grp; // assign from Inspector

grp. // where are the mute / solo API?
1 Like

You can either use mixer snapshots and transition to one of those snapshots, or you can expose any of the settings (like volume) for code, then use the exposed setting in your code (via AudioMixer.)

Snapshots are overkill. I only want to change the mute status of a couple Groups, nothing more. How do we expose the mute button for a Group and set it from code?

I don’t understand why this needs to be done. I have no idea why they didn’t just put the mute and solo switches into the normal API. It would be very useful.

6 Likes

Why is a snapshot overkill? You can transition to it with a duration of zero, effectively muting all your desired groups at once. Also, it is nicer to configure the snapshot from the editor than having to hardwire the muting into your code.

The mute button itself cannot be exposed to scripting, it seems. Instead, you just select any group, then in the inspector, right-click on the “Volume” label, and select “Expose ‘Volume …’ to script.” Then in your script, you can do this:

mixer.SetFloat(“volume”, 0f);

The muting would be far more useful for what I’m trying to do. Since I want to have a separately mutable music volume, SFX volume and ambient volume, that means I’d need to create 2x2x2 = 8 snapshots to get all the mute combinations? Ludicrous.

Snapshots are great for some things, but the mute control should still be exposed automatically from code. No solution to this?

I don’t necessarily want to set the volume…just mute it. I don’t want to lose the volume level previously set.

6 Likes

I’ve come to the same conclusion.
I’m looking into the mixer for a procedural project (using Master Audio) and while the manual looks great you can’t seem to access anything low level.

How you you control any of the mixer FX from code, for example?

FX params: right click, select expose parameter, name your param, enjoy. Only floats, only from the main thread.

ty!

Is there a doc reference for that? Because there should be!

Also: how do you reference the effect? I don’t see any class for them?

ah…I see
http://unity3d.com/learn/tutorials/modules/beginner/5-pre-order-beta/exposed-audiomixer-parameters

No. Granted, the snapshots are mixer-wide, but you can always create sub-mixers. In your case, you could create separate mixers for music, sfx, and ambient, all of which only have the default “Master” group. Then, you can route those mixers into your main mixer. For the three mixers, you can set up snapshots to mute them separately.

I agree. I don’t think it is possible right now, though.

I see. It wasn’t clear to me you wanted to “keep” the previous volume.

1 Like

Ok, thanks. Is there somewhere we can “ask for” this capability to be added?

I’d say the issue tracker should be a good place.

2 Likes

Is there performance savings by using the mute vs. setting the volume to 0?
This was my only motivation for trying to use it.

Umm… Even exposing the volume parameter isnt working for me. I get an error CS1061 saying
Type ‘UnityEngine.Audii.AudioMixerGroup’ doe not contain a definition for ‘SetFloat’ and no extention method ‘SetFloat’ of typr ‘UnityEngine.Audio.AudioMixerGroup’ could be found. Are you missing an assembly reference?
Sorry for the noob question

YourAudioMixerGroup.audioMixer.SetFloat(“MyExposedParamName”, 0f);

https://feedback.unity3d.com/suggestions/expose-api-for-audiomixergroup-and-audioeffects-audiomixer-parameters

https://answers.unity.com/questions/966255/mute-audiomixergroup-through-script.html?childToView=1505802#answer-1505802

Bumping this.
Has there been any update concerning the exposure of Solo, Mute and Bypass modes?
I find myself having the same need as jerotas here with music and sfx, I have combinations of volumes management AND options to entirely mute content. It seemed more intuitive to work with these functions than fiddle with a maze of mixers.

Nevertheless, using an array of sub-mixers does work, notably by creating snapshots for MSB options, but it is over-engineered and not edit-friendly: I didn’t find a way to copy portions of the Groups hierarchy of my main mixer into the new and separate sub-mixers. It’s absurd how much time I’m wasting recreating entire parts of the main Groups hierarchy. Right-clicking on any Group doesn’t reveal anything useful such as Copy/Paste options!

Finally, exposing certain variables could really be made much more accessible and obvious in the Inspector.

2 Likes

THIS!

It’s sometimes increadibly frustrating to work with Unity when issues like this have been around for so long. Everything new and shiny gets mostly/half finished before the next big exciting thing comes along, and old core features such as this just get left to rot. This thread is nearly 5 years old and we still can’t unmute a mixer channel

6 Likes

yeah its a little insane im not gonna lie that they have time to make things as lowlevel as DOTS but take long to expose such API as this

1 Like

I agree. Unity is wild for not just exposing the Mute, Solo, and Bypass into the API. It’s not complicated… :eyes: I expect more from them…

1 Like