Performance: Audio mixer
Audio mixers affect how audio is processed and mixed in real-time, impacting CPU usage and audio latency.
Jump into concepts and practice - no test required
AudioMixer mixer = new AudioMixer(); mixer.AddEffect("Reverb"); // Group audio sources and apply effects once per group instead of individually
AudioMixer mixer = new AudioMixer(); mixer.AddEffect("Reverb"); mixer.AddEffect("Echo"); mixer.AddEffect("Distortion"); // Apply effects to every audio source individually
| Pattern | CPU Usage | Latency | Audio Quality Impact | Verdict |
|---|---|---|---|---|
| Applying many effects per audio source | High | High | Good but costly | [X] Bad |
| Grouping sources and applying effects once | Low | Low | Good balance | [OK] Good |
AudioMixer in Unity?MasterVolume to -20 decibels in an AudioMixer called audioMixer?AudioMixer mixer;
mixer.SetFloat("MusicVolume", -10f);
float volume;
mixer.GetFloat("MusicVolume", out volume);
Debug.Log(volume);
What will be printed in the console?AudioMixer mixer; mixer.SetFloat(MusicVolume, -80f);
SetFloat inside a coroutine?audioMixer.SetFloat("MasterVolume", value) each frame correctly describes decreasing volume gradually and calling SetFloat repeatedly. Set audioMixer.SetFloat("MasterVolume", -80) once and wait 3 seconds sets volume once, no fade. Use audioMixer.SetFloat("MasterVolume", 80) to increase volume over time increases volume incorrectly. Change the AudioSource volume property instead of AudioMixer changes AudioSource, not AudioMixer.