Course contentsShow
← Unity Game Development
Lesson 338 of 8285. UI and Audio SystemsFree lesson

Managing Audio Mixer Groups for Master Control

Learners will route multiple audio sources into mixer groups to apply global effects and adjust volume levels for specific sound categories.

In this lesson, you will learn how to organize your game's soundscape by routing multiple AudioSource components into specific Mixer Groups to achieve global volume control and unified effects.

Why Use Audio Mixer Groups?

Imagine your game has dozens of sound effects—footsteps, UI clicks, and combat impacts. If you want to lower the volume of all sound effects without affecting the music, adjusting each AudioSource individually is inefficient and messy. An AudioMixer acts like a central routing hub, allowing you to categorize sounds into groups (e.g., "Master," "Music," "SFX") and control them as a single unit.

Setting Up the Hierarchy

To create a control structure, first create an AudioMixer asset in your Project window. Inside the mixer, you can define a hierarchy of groups. For example, you might create a "Music" group and an "SFX" group, both nested under a "Master" group.

  1. Create the Mixer: Right-click in the Project window > Create > Audio Mixer.
  2. Define Groups: Open the Mixer window and click the + icon in the Groups section to add "Music" and "SFX."
  3. Route Sources: Select an AudioSource in your scene. In the Inspector, look for the Output field. Drag your specific Mixer Group (e.g., "SFX") into this slot.

Controlling Volume via Script

Once routed, you can easily control the volume of an entire category using the AudioMixer API. Since AudioMixer handles these values in decibels (dB), you must expose the volume parameter in the mixer window (Right-click the volume fader in the Mixer window > Expose 'Volume' to script) to interact with it:

using UnityEngine;
using UnityEngine.Audio;

public class VolumeController : MonoBehaviour
{
    public AudioMixer mainMixer;

    public void SetSFXVolume(float sliderValue)
    {
        // Convert normalized 0-1 slider value to decibels
        mainMixer.SetFloat("SFXVolume", Mathf.Log10(sliderValue) * 20);
    }
}

By routing sounds into these containers, you ensure that global adjustments—like a "Mute All" button or a Master Volume slider—only require a single line of logic.

Key Takeaway: Audio Mixer Groups allow you to group multiple sound sources into logical categories, enabling efficient global volume management and collective effect processing.