C# Setting AudioMixerGroup through code
I have a Mixer with a group called 'ExplosivesGroup' it´s in the group because i want all explosives to have a custom preset- now i COULD go to the AudioSource and drag´n drop in the inspector.
But how is this done through scripting?
All i have to go after is the String 'ExplosivesGroup'.
Answer by okkal11 · Apr 22, 2015 at 09:29 PM
This seems to work :)
//First set the mixer that contains the actual group.
AudioMixer mixer = Resources.Load("MasterMixer") as AudioMixer;
//then we can search for the string like this
string _OutputMixer = "ExplosivesGroup";
GetComponent<AudioSource>().outputAudioMixerGroup = mixer.FindMatchingGroups(_OutputMixer)[0];
Thanks This helped me too. However:
Can you also create a audiomixer and child groups? I've searched my way through google and already was happy to find this post.
Cheers
Remember to add on top of the C# script the line:
using UnityEngine.Audio;
This solved my issue, and four years later at that ;). Thanks!
Answer by Westland · Feb 01, 2019 at 12:15 AM
Alternatively, using singletons, create a public audiomixergroup variable and set it in the Editor Inspector, and set other audiosource's output to that.
Note, this might be bad for reasons I don't know but people keep saying it is, global variables and stuff. But another way of doing it irregardless
Well, it doesn't need to be a singleton to assign it and use it. So thank you, it still helps.
Your answer
Follow this Question
Related Questions
How do I get the parent from a AudioMixerGroup Object 2 Answers
Audio help 0 Answers
Second AudioClip won't play 0 Answers
Listening to Sound Card Output 0 Answers
Second AudioClip won't play 0 Answers