Loading lessons...
Audio Mixer
Audio Mixer
An Audio Mixer asset allows you to group, route, mix, and apply effects to various audio sources in your game (e.g. separate controls for Music, Sound Effects, and Dialog).
Creating and Routing
- Right-click in the Project Window and select Create -> Audio Mixer.
- Open the Audio Mixer window (Window -> Audio -> Audio Mixer).
- Create Groups in a hierarchical tree (e.g., Master -> Music, Master -> SFX).
- Select an Audio Source component, and assign its Output field to a specific mixer group.
Volume Control and Exposed Parameters
You can adjust group volume levels in the mixer editor. To modify group volume via script (e.g. for a settings slider):
- Select the mixer group.
- Right-click the Volume property in the Inspector and select Expose to script.
- In the Audio Mixer parameters dropdown, rename the parameter (e.g. "MusicVol").
using UnityEngine.Audio;
public class SettingsMenu : MonoBehaviour
{
public AudioMixer mixer;
public void SetMusicVolume(float volume)
{
// Set mixer volume parameter using decibel values
mixer.SetFloat("MusicVol", volume);
}
}
Audio Ducking
Ducking automatically lowers the volume of one group when another group plays (e.g., lowering music volume when a character speaks).
- You add a Send effect to the Speech group.
- Add a Duck Volume effect to the Music group.
- Route the Speech Send to the Music Duck input.
TL;DR
- Audio Mixers group and balance game audio.
- Route Audio Source components to Mixer Groups.
- Expose mixer variables to control volumes via scripts using decibels.
- Implement Audio Ducking to keep dialog clear over music tracks.