Version: Unity 6.2 (6000.2)
LanguageEnglish
  • C#

AudioMixerGroup

class in UnityEngine.Audio

/

Inherits from:Object

/

Implemented in:UnityEngine.AudioModule

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Description

Object representing a group in the mixer.

Used to route audio to specific channels in an AudioMixer, allowing for grouped processing and effects.

Commonly used for managing different categories of sounds, like music, sound effects (SFX), and dialogue with shared volume controls and audio effect settings.

AudioMixerGroups can be nested for more complex audio hierarchies. Typically, a root "Master" group is used that contains multiple specific groups like "Music", "SFX" and "Dialogue".

using UnityEngine;
using UnityEngine.Audio;

// Example of a class that manages audio in a game public class AudioManager : MonoBehaviour { // References to the AudioMixer and AudioSources public AudioMixer audioMixer; public AudioSource musicSource; public AudioSource sfxSource;

// Handles to the AudioMixerGroups private AudioMixerGroup musicGroup; private AudioMixerGroup sfxGroup;

private void Start() { // Find the AudioMixerGroups and set the output of the AudioSources to them musicGroup = audioMixer.FindMatchingGroups("Music")[0]; musicSource.outputAudioMixerGroup = musicGroup;

sfxGroup = audioMixer.FindMatchingGroups("SFX")[0]; sfxSource.outputAudioMixerGroup = sfxGroup;

SetMusicVolume(0.8f); SetSFXVolume(1.0f); }

public void SetMusicVolume(float volume) { // Set the volume of the Music group in the AudioMixer // Volume needs to be exposed in the AudioMixer audioMixer.SetFloat("MusicVolume", volume); }

public void SetSFXVolume(float volume) { // Set the volume of the SFX group in the AudioMixer // Volume needs to be exposed in the AudioMixer audioMixer.SetFloat("SFXVolume", volume); } }

Note: Create your AudioMixerGroups in the editor before referencing them in code.

Additional resources: AudioMixer, AudioSource, AudioListener.

Properties

Property Description
audioMixerGain access to the AudioMixer that this AudioMixerGroup belongs to (Read Only).

Inherited Members

Properties

PropertyDescription
hideFlagsShould the object be hidden, saved with the Scene or modifiable by the user?
nameThe name of the object.

Public Methods

MethodDescription
GetInstanceIDGets the instance ID of the object.
ToStringReturns the name of the object.

Static Methods

MethodDescription
DestroyRemoves a GameObject, component or asset.
DestroyImmediateDestroys the object obj immediately. You are strongly recommended to use Destroy instead.
DontDestroyOnLoadDo not destroy the target Object when loading a new Scene.
FindAnyObjectByTypeRetrieves any active loaded object of Type type.
FindFirstObjectByTypeRetrieves the first active loaded object of Type type.
FindObjectsByTypeRetrieves a list of all loaded objects of Type type.
InstantiateClones the object original and returns the clone.
InstantiateAsyncCaptures a snapshot of the original object (that must be related to some GameObject) and returns the AsyncInstantiateOperation.

Operators

OperatorDescription
boolDoes the object exist?
operator !=Compares if two objects refer to a different object.
operator ==Compares two object references to see if they refer to the same object.