- Home /
How to bypass audio effects from script? (AudioMixer)
For my game, I intend to make heavy use of audio effects in Unity 5's AudioMixer. I understand how to expose parameters to control them from script.
But how do I bypass audio effects from script (to conserve cpu)? There seems to be no "enabled" property or parameter that I could set in the inspector, where other exposable parameters show up. There is only the toggle button in the mixer view itself.
Surely it's possible to do that from script?
Answer by SoftAnswers · Feb 13, 2016 at 03:31 AM
your AudioSourceGameobject.SetActive(true/false);
Weirdly, I've only seen this more than 2 years later.... :D
I'm constantly routing multiple audio sources to a mixer channel and want to still use the channel, but sometimes disable its audio effects. setting the AudioSource to inactive won't achieve what I want, unfortunately.
Answer by moff84 · Mar 08, 2018 at 07:32 PM
Use snapshots. Have one with the effect on and one with it off. You can script to transitionTo another snapshot
Thank you for your answer.
However, snapshots are not the solution for my use case. They are great when you have a handful of configurations you want to switch between, but with the granular changes I'm making all the time, that would be very messy and error-prone to solve with snapshots.
I guess I could create a sub mixer per channel as a workaround, is that what you meant? But that is also quite clunky and just seems like overkill. I don't quite understand what criteria they used to deter$$anonymous$$e which mixer parameters were to be exposable and which weren't...
Answer by DerLasseHenrich · Sep 23, 2019 at 09:31 PM
You can say audioSource.outputAudioMixerGroup = null. To enable that mixer later, simply assign it again.
Thank you for the suggestion. If it were just a single track where I want to "switch on/off" a single audio effect, I guess that would be a good work-around. However, I'd like to do so with multiple tracks and, more importantly, switch various effects on a channel on and off from code, so if there's two audio effects, that would already mean creating 4 different audio mixers for the various constellations, while also managing their snapshots etc. Sounds like a hard to maintain mess.
It's baffling the obvious simple solution of being able to enable/disable audio effects from code is still not possible 3 and half years later....