In this lesson, you will learn how to configure side-chaining in the Unity Audio Mixer to automatically lower the volume of your background music whenever critical dialogue plays.
The Concept of Ducking
Audio ducking is a technique where the volume level of one audio signal (typically background music or ambient noise) is automatically reduced when another signal (like character dialogue) is active. Think of a radio DJ talking over a music track; the music automatically "ducks" down so the listener can clearly hear the announcer. In Unity, we achieve this using the Audio Mixer and the Duck Volume effect.
Setting Up the Side-Chain
To implement this, you need two distinct channels in your Audio Mixer: a "Music" group and a "Dialogue" group.
- Configure the Music Group: Select your Music Mixer Group and add the
Duck Volumeeffect from the "Add Effect" menu. - Assign the Source: In the
Duck Volumesettings, you need to point the "Source" to the Dialogue Mixer Group. This tells the Music group to listen to what is happening in the Dialogue group. - Threshold and Ratio: Set the Threshold to determine how loud the dialogue needs to be before ducking kicks in, and the Ratio to determine how much the music should be lowered.
A Quick Scripting Hook
While the Mixer handles the routing, you often trigger this via your dialogue system. By exposing the volume parameter of your Music group to the mixer, you can also control the transition speed:
public AudioMixer masterMixer;
public void TriggerDucking(bool isTalking)
{
// Smoothly transition the volume parameter
float targetVol = isTalking ? -20f : 0f;
masterMixer.SetFloat("MusicVolume", targetVol);
}
By linking the Duck Volume effect to your Dialogue channel, you ensure that no matter how intense your soundtrack becomes, the player will never miss an important narrative beat. This keeps your soundscape clean and prevents "frequency clutter," where too many sounds fight for the player's attention.
Key Takeaway: Dynamic ducking uses side-chaining to prioritize critical audio signals, ensuring clear communication by automatically reducing background intensity when necessary.