Search Unity

Question How to enable or disable effects on audio mixer at runtime?

Discussion in 'Audio & Video' started by valentin56610, Sep 5, 2022.

  1. valentin56610

    valentin56610

    Joined:
    Jan 22, 2019
    Posts:
    156
    Hi there,

    I am trying to enable or disable low pass effect on my audio mixer at runtime (enable it when my player is shell shocked to make all sounds deeper to simulate temporary deaf)

    I tried googling but it seems nobody is even trying to do so? Like I am the only one having this issue

    So, how am I supposed to do this? I thought enabling or disabling effects at runtime would be the easiest solution, seems it is not ...
     
    CloudyVR, benmrx and MrDizzle26 like this.
  2. Jakub_Machowski

    Jakub_Machowski

    Joined:
    Mar 19, 2013
    Posts:
    647
    We have exactly the same problem, Ist sometimes quite funny like unity can't implement so obvious things like disabling sound effect by code. I still cant find any solution for that.
     
    MrDizzle26 likes this.
  3. valentin56610

    valentin56610

    Joined:
    Jan 22, 2019
    Posts:
    156
    Thanks for bumping up the thread, still no luck on my end either...
     
  4. imakegames3

    imakegames3

    Joined:
    May 18, 2022
    Posts:
    1
    I think the way to do this is to is with AudioMixer snapshots. this video will explain it better than I can.
     
  5. valentin56610

    valentin56610

    Joined:
    Jan 22, 2019
    Posts:
    156
    Thank you
     
  6. Jakub_Machowski

    Jakub_Machowski

    Joined:
    Mar 19, 2013
    Posts:
    647
    This is not a fix for a problem.
     
    CloudyVR likes this.
  7. MrDizzle26

    MrDizzle26

    Joined:
    Feb 8, 2015
    Posts:
    36
    +1 for being able to bypass fx channels in code
     
  8. ReprWasTaken

    ReprWasTaken

    Joined:
    Sep 18, 2021
    Posts:
    1
    You can use mixer.SetFloat to change the cutoff frequency of your lowpass filter (after exposing that variable). When you want the effect on, set the value low, but when you want it off, change it to 22000. Remember to import Unity.Audio into your script!
     
  9. MrDizzle26

    MrDizzle26

    Joined:
    Feb 8, 2015
    Posts:
    36
    Can you confirm no audio processing is happening when you do that though? Without the ability to disable/bypass an audio FX through code, each solution to turn it "off" is custom and doesn't stop the processing from happening.
     
  10. Zuuunk

    Zuuunk

    Joined:
    Jul 28, 2021
    Posts:
    11
    It is also my hunch that there is still processing behind the scenes. We can only assume that if they were thoughtful enough to turn it off when you crank to the max would have thought to put a programmable bypass in as well.

    You can't even bypass it on one snapshot and have it enabled on another. It's insane something so obvious for performance would be omitted from a game engine. Unity's audio tooling is complete trash.
     
    CloudyVR and MrDizzle26 like this.
  11. AMO_Noot

    AMO_Noot

    Joined:
    Aug 14, 2012
    Posts:
    433
    I can't simply turn on/off audio effects without having them constantly processing it in the background? If that's true, then that is absolutely INSANE.
     
    Last edited: Dec 21, 2023
    forestrf and valentin56610 like this.
  12. forestrf

    forestrf

    Joined:
    Aug 28, 2010
    Posts:
    230
    I'm not 100% sure because I didn't test it on a player, but
    AudioMixerGroup
    are actually
    AudioMixerGroupController
    , an internal class that could be accessed through reflection and which has the parameters
    bypassEffects
    ,
    solo
    ,
    mute
    and even a list of effects.

    It reminds me of the AnimatorController, which has a similar class related to it that can't be used on a build, but this seems it would work.
     
  13. SeventhString

    SeventhString

    Unity Technologies

    Joined:
    Jan 12, 2023
    Posts:
    410
    I doubt it's that bad... I agree there is much to do but come on :p have some faith! We love sound at least as much as you do. I'll have a look at this because it's a valid concern, but I'm hopeful. A quick scan in the code base reveals the existence of a few bypass-like variables, but it's always complicated to jump the hoops between Unity and FMOD. To be continued...
     
    MrDizzle26 and forestrf like this.
  14. MrDizzle26

    MrDizzle26

    Joined:
    Feb 8, 2015
    Posts:
    36
    I'm delighted to have some communication on this, thanks for taking a look.
     
  15. SeventhString

    SeventhString

    Unity Technologies

    Joined:
    Jan 12, 2023
    Posts:
    410
    After some digging, I can confirm that bypassed effects are not being processed when turned off. When the "wetness" of an effect is detected as 0, it automatically set the bypass flag, effectively NOT calling the processing function of the plugin.
     
    Last edited: Jan 23, 2024
    MrDizzle26 and forestrf like this.