In this lesson, you will learn how to build a tree-like routing architecture for your audio signals, allowing you to control groups of sounds simultaneously without affecting others.
When working on a complex project, controlling every single AudioSource individually is impossible. By designing a hierarchical structure, you create a "parent-child" relationship where audio flows from specific sources up through increasingly broader mixer groups.
The Routing Tree
Think of your audio mixer as a company hierarchy. At the top, you have the Master group. Underneath, you create sub-groups like "Music," "SFX," and "Ambience." You can further nest these: for instance, under "SFX," you might have "Player," "Enemies," and "UI."
This structure allows you to apply effects or volume changes at different levels. If you want to turn down all enemy combat sounds, you simply adjust the "Enemies" group volume, and every sound routed to that group will decrease automatically. If you want to mute the entire game, you just drop the "Master" group volume.
Setting Up the Hierarchy
In the Audio Mixer window, you define these relationships using the "Groups" panel. You can drag and drop one group onto another to make it a child.
When you assign an AudioSource to a specific group, the signal path looks like this:
AudioSource → Sub-Group (e.g., Enemy) → Parent Group (e.g., SFX) → Master.
// Example of assigning a source to a specific sub-group in code
public AudioSource enemyExplosion;
public AudioMixerGroup enemyGroup;
void Start() {
// Dynamically route the audio source to the Enemy group in the hierarchy
enemyExplosion.outputAudioMixerGroup = enemyGroup;
}
By keeping this structure clean, you avoid "spaghetti routing" where sounds are hard to track. A well-organized hierarchy acts like a control panel, letting you apply a Reverb effect to the entire "Environment" branch without touching your "UI" or "Music" tracks, keeping your game's soundscape balanced and professional.
Key Takeaway: A hierarchical mixer structure enables granular control over categories of sound, allowing you to manipulate entire branches of your audio routing tree with a single adjustment.