Search Unity

How do you mute a AudioMixerGroup from code?

Discussion in 'Audio & Video' started by jerotas, Mar 10, 2015.

  1. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,071
    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?

    Code (csharp):
    1.  
    2. public AudioMixerGroup grp; // assign from Inspector
    3.  
    4. grp. // where are the mute / solo API?
    5.  
     
  2. blizzy

    blizzy

    Joined:
    Apr 27, 2014
    Posts:
    775
    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.)
     
  3. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,071
    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.
     
    Last edited: Mar 10, 2015
    phobos2077 and Zelek like this.
  4. blizzy

    blizzy

    Joined:
    Apr 27, 2014
    Posts:
    775
    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);
     
  5. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,071
    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.
     
    paulomuggler, Anisoropos and Zelek like this.
  6. sonicviz

    sonicviz

    Joined:
    May 19, 2009
    Posts:
    1,033
    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?
     
  7. gregzo

    gregzo

    Joined:
    Dec 17, 2011
    Posts:
    795
    FX params: right click, select expose parameter, name your param, enjoy. Only floats, only from the main thread.
     
  8. sonicviz

    sonicviz

    Joined:
    May 19, 2009
    Posts:
    1,033
    Last edited: Mar 11, 2015
  9. blizzy

    blizzy

    Joined:
    Apr 27, 2014
    Posts:
    775
    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.
     
    Zelek likes this.
  10. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,071
    Ok, thanks. Is there somewhere we can "ask for" this capability to be added?
     
  11. blizzy

    blizzy

    Joined:
    Apr 27, 2014
    Posts:
    775
    I'd say the issue tracker should be a good place.
     
    phobos2077 and jerotas like this.
  12. FlyingHighUp

    FlyingHighUp

    Joined:
    Apr 23, 2012
    Posts:
    14
    Is there performance savings by using the mute vs. setting the volume to 0?
    This was my only motivation for trying to use it.
     
  13. Anjoom

    Anjoom

    Joined:
    May 15, 2017
    Posts:
    3
    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
     
  14. dylansunkel

    dylansunkel

    Joined:
    Jun 4, 2016
    Posts:
    1
    YourAudioMixerGroup.audioMixer.SetFloat("MyExposedParamName", 0f);
     
  15. PixelLifetime

    PixelLifetime

    Joined:
    Mar 30, 2017
    Posts:
    55
  16. OSMET

    OSMET

    Joined:
    Jun 22, 2017
    Posts:
    2
  17. Starbox

    Starbox

    Joined:
    Sep 17, 2014
    Posts:
    59
    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.
     
  18. empika

    empika

    Joined:
    Jul 12, 2012
    Posts:
    24
    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
     
    jerotas likes this.
unityunity