0
0
Unityframework~10 mins

Audio mixer in Unity - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Audio mixer
Start
Create AudioMixer
Add Audio Groups
Assign Audio Sources to Groups
Adjust Volume/Effects
Play Audio
Modify Mixer Parameters at Runtime
Stop or Change Audio
End
This flow shows how an audio mixer is created, groups are added, audio sources assigned, parameters adjusted, and audio played or modified in Unity.
Execution Sample
Unity
using UnityEngine;
using UnityEngine.Audio;

public class AudioMixerExample : MonoBehaviour {
    public AudioMixer mixer;
    void Start() {
        mixer.SetFloat("MusicVolume", -10f);
    }
}
This code sets the volume of the 'MusicVolume' parameter in an AudioMixer to -10 decibels when the game starts.
Execution Table
StepActionEvaluationResult
1Start method calledN/ABegin execution
2Call mixer.SetFloat("MusicVolume", -10f)Set parameter 'MusicVolume' to -10Volume parameter updated
3AudioMixer applies new volumeVolume changes to -10 dBAudio output volume lowered
4End of Start methodN/AReady to play audio with new volume
💡 Start method finishes; AudioMixer parameter set successfully
Variable Tracker
VariableStartAfter Step 2Final
mixer parameter 'MusicVolume'default (e.g., 0 dB)-10 dB-10 dB
Key Moments - 2 Insights
Why does changing the mixer parameter affect all audio sources assigned to that group?
Because the AudioMixer parameter controls the volume or effect for the entire group, so all audio sources routed through that group are affected together, as shown in step 3 of the execution_table.
What happens if the parameter name passed to SetFloat does not exist?
The parameter will not change, and no error is thrown immediately, so the volume stays the same. This is why it's important to use exact parameter names defined in the AudioMixer asset.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the value of 'MusicVolume' after step 2?
A10 dB
B-10 dB
C0 dB
DUndefined
💡 Hint
Check the 'Result' column in row 2 of the execution_table.
At which step does the AudioMixer apply the new volume to the audio output?
AStep 3
BStep 2
CStep 1
DStep 4
💡 Hint
Look for when the audio output volume changes in the execution_table.
If you change the parameter name in SetFloat to a wrong name, what will happen according to the key moments?
AThe volume will still change
BUnity throws an error immediately
CThe parameter will not change and no error occurs
DAudio stops playing
💡 Hint
Refer to the second key moment about parameter names.
Concept Snapshot
Audio Mixer in Unity:
- Create AudioMixer asset and add groups
- Assign AudioSources to groups
- Use SetFloat("ParamName", value) to adjust volume/effects
- Changes affect all audio in that group
- Parameter names must match exactly
- Modify parameters at runtime for dynamic audio control
Full Transcript
This visual execution shows how an AudioMixer in Unity controls audio volume by setting parameters. First, the Start method runs and calls SetFloat to set the 'MusicVolume' parameter to -10 decibels. This change affects all audio sources assigned to the music group, lowering their volume. The execution table traces each step, showing the parameter change and its effect. Key moments clarify why group parameters affect multiple sources and what happens if a wrong parameter name is used. The quiz tests understanding of parameter values and execution steps. The snapshot summarizes how to use AudioMixer parameters to control audio dynamically in Unity.