[Solved] Find all AudioMixerGroups

Hello I’m having some problems with finding all the AudioMixerGroups in my unity project.

I want to add a AudioMixerGroup to a AudioSource with my scripts.

Am I wrong in assuming this would be the correct way of finding my desired AudioMixerGroup:

foreach (AudioMixerGroup AMG in FindObjectsOfType<AudioMixerGroup>())
        {
            if (AMG.name == "Sound")
            {
                audioSource.outputAudioMixerGroup = AMG;
                break;
            }
        }

But this just results in nothing as it can’t find any AudioMixerGroups :frowning:

I have some experience with Mixer Groups give me like 5-10 minutes I’ll have a script together for you that shows how you can get what you are looking for.

1 Like

Many thanks! I will wait in anticipation! :smile:

Here’s a sample script that will do what you are looking for. I had a similar problem to solve when I was working on my object pooling asset; it’s available from the asset store link in my signature(shameless plug).

using UnityEngine;
using UnityEngine.Audio;

public class AudioExtension : MonoBehaviour {

    public AudioMixer audioMixer;

    public AudioMixerGroup[] AllMixerGroups {
        get{
            return audioMixer.FindMatchingGroups(string.Empty);
        ;}
    }
}

Essentially what you want to do is create a public variable for the audio mixer you want to get groups from. Drag your AudioMixer onto that variable in the inspector and use the extension method to return all the mixer groups associated with that mixer. Simple as that! Good luck and I hope this helps you out!

4 Likes

Also, if you are looking for a specific mixer group you can just replace the string.Empty with the string that represents the path to your mixer group. eg “Sound” :wink:

That’s as easy as this:

 audioSource.outputAudioMixerGroup = audioMixer.FindMatchingGroups("Sound")[0];
3 Likes

Works perfectly! Many thanks!

No worries. If you have any more questions you can get at me on Twitter or via my website. Links are in my signature. Best of luck in all your endeavours!

I was stuck on this for a few minutes only to realize I was using AudioMixer.outputAudioMixerGroup instead of AudioSource.outputAudioMixerGroup.

is there a way to find out what AudioMixerGroup is feeding into what other AudioMixerGroup?

I don’t think it is possible in a C# script. I suspect what you see in the editor window is just a representation from the C++ side (FMod).

solution is found here:
https://answers.unity.com/questions/1735647/how-do-i-get-the-parent-from-a-audiomixergroup-obj.html?childToView=1754019#answer-1754019