AudioMixerGroup
Object representing a group in the mixer.
Read time 5 minutesLast updated 6 days ago
Definition
- Type: Class
- Namespace: UnityEngine.Audio
- Assembly: UnityEngine.AudioModule
- Inherits from: Object
public class AudioMixerGroup : Object
Remarks
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 gamepublic 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.
Properties
Property | Description |
|---|---|
| audioMixer | Gain access to the AudioMixer that this AudioMixerGroup belongs to (Read Only). |
Inheritance
Operators
Operator | Description |
|---|---|
| operator == | Compares two object references to see if they refer to the same object. |
| bool | Determines whether the object exists. |
| operator != | Compares if two objects refer to a different object. |