Course contentsShow
← Unity Game Development
Lesson 343 of 8285. UI and Audio SystemsFree lesson

Automating Mixer Parameters for Interactive Audio

Learners will use the automation lane to dynamically control volume, pitch, and effect levels in response to specific game events or player actions.

In this lesson, you will learn how to automate Audio Mixer parameters to create dynamic, responsive soundscapes that react to player actions in real-time.

Bringing Audio to Life with Automation

While Mixer Snapshots allow for instant transitions between global audio states, Automating Mixer Parameters gives you granular, frame-by-frame control. Think of this as "keyframing" your audio: instead of just turning a sound on or off, you can programmatically slide a volume knob, shift a pitch value, or increase a filter’s intensity as the game state changes.

Exposing Parameters

To control a mixer value from a script, you must first "expose" it.

  1. Open your Audio Mixer window.
  2. Select the specific group (e.g., "Music" or "SFX").
  3. In the Inspector, right-click the property you want to change (like Volume or Pitch) and select Expose '[ParameterName]' to script.
  4. In the Mixer’s "Exposed Parameters" tab, rename it to something easy to use, like MusicVolume.

Driving Values via Script

Once exposed, you can use the AudioMixer class to modify these values during gameplay. This is perfect for situations like lowering background music volume when a player opens a UI menu or increasing a low-pass filter’s cutoff as a player's health drops.

using UnityEngine;
using UnityEngine.Audio;

public class AudioController : MonoBehaviour
{
    public AudioMixer mainMixer;

    public void SetMusicVolume(float sliderValue)
    {
        // Convert linear slider (0 to 1) to the logarithmic decibel scale
        // Audio Mixer expects a value between -80dB and 0dB
        float volume = Mathf.Log10(sliderValue) * 20;
        mainMixer.SetFloat("MusicVolume", volume);
    }
}

By connecting this method to a UI slider’s callback function (which we covered in previous lessons), you create a seamless bridge between player input and the audio engine. You can also use Update() or a Coroutine to smoothly lerp these values over time, creating professional, responsive sound transitions that react to game events like combat intensity or environmental hazards.

Key Takeaway: Exposing mixer parameters allows you to link real-time game data directly to audio properties, transforming static mixes into dynamic, responsive soundscapes.