Complete Audio Manager Tutorial

What is the Audio Manager?

The Audio Manager is the core brain of your entire audio system. It's a singleton component that controls all audio playback, manages audio sources, handles volume settings, and provides the API for playing sounds throughout your game.

Finding the Audio Manager

After Quick Setup:

  • Look in your Hierarchy for "USM" GameObject

  • Select it to see the USM component in the Inspector

Manual Check:

  • If no USM exists, go to Tools → USM → Quick Setup

Understanding the Audio Manager Components

Main Settings in Inspector:

Configuration Section:

  • Audio Library: Reference to your audio database

  • Initial Pool Size: Number of audio sources to create (default: 20)

  • Global Volume: Master volume affecting all sounds (0.0 to 1.0)

  • Music Volume: Volume for music tracks only (0.0 to 1.0)

  • SFX Volume: Volume for sound effects only (0.0 to 1.0)

What Each Setting Does:

Audio Library:

  • This is the database containing all your audio assets

  • Automatically assigned during Quick Setup

  • Contains all your SFX and Music definitions

Initial Pool Size:

  • Pre-creates this many Audio Source components

  • Prevents runtime allocation stalls

  • 20 is good for most games, increase for audio-heavy games

Volume Controls:

  • Global Volume: Affects EVERY sound (like master volume on a stereo)

  • Music Volume: Only affects music tracks

  • SFX Volume: Only affects sound effects

  • All volumes are multiplied together for final output

How the Audio Manager Works

The Singleton Pattern:

  • Only ONE Audio Manager can exist per scene

  • Automatically available via USM.

  • Accessible from anywhere in your code

  • Survives scene changes if configured

Audio Source Pooling:

  • Creates a pool of Audio Source components at startup

  • Reuses them instead of creating/destroying constantly

  • Prevents audio crackles and performance issues

  • Automatically manages free audio sources

Smart Audio Management:

  • Automatic cleanup: Stops finished sounds and returns sources to pool

  • Volume mixing: Applies global + category + individual volumes

  • Priority system: Manages limited audio hardware resources

  • Spatial audio: Handles 2D and 3D sound positioning

Basic Audio Manager Setup

Step 1: Initial Configuration

  1. Select the USM in Hierarchy

  2. In Inspector, set your preferred volumes:

    • Global Volume: 1.0 (full volume)

    • Music Volume: 0.8 (80% - typically lower than SFX)

    • SFX Volume: 1.0 (100% - sound effects at full volume)

Step 2: Pool Size Adjustment

  • For simple games: 10-15 audio sources

  • For action games: 20-30 audio sources

  • For audio-intensive games: 30-50 audio sources

  • Don't set too high - wastes memory

Step 3: Audio Library Assignment

  • Make sure the Audio Library field is assigned

  • If empty, click the circle and select your Audio Library asset

  • Usually found at: Assets/Kitler dev/USM/Data/

Playing Sounds with the Audio Manager

// Play a sound effect
USM.PlaySFX(Audio.Sounds.Explosion);

// Play background music
USM.PlayMusic(Audio.Sounds.BackgroundMusic);

// Play sound at specific position
USM.PlaySFXAtPosition("Gunshot", transform.position);

// Play sound attached to GameObject
USM.PlaySFXAttached("Engine", gameObject);

Method 2: Builder Pattern (Advanced Control)

// Chain multiple settings together
USM.PlaySFX(Audio.Sounds.Explosion)
   .SetVolume(0.8f)
   .SetPitch(1.2f)
   .SetPosition(new Vector3(10, 0, 5))
   .SetLoop(true);

Method 3: Using Auto-Generated Names

Your created Audio will show here in the Audio.Sounds

// After creating sounds, use these clean names:
USM.PlaySFX(Audio.Sounds.Explosion);
USM.PlayMusic(Audio.Music.MainTheme);

Music Management

Playing Background Music:

// Basic music playback
USM.PlayMusic(Audio.Music.BackGroundMusic);

// Music with fade in
USM.PlayMusic(Audio.Music.BackGroundMusic).SetVolume(1).SetPitch(1); // 2-second fade

// Crossfade between music tracks
USM.CrossfadeMusic(Audio.Music.BackGroundMusic,0.3f); // 3-second crossfade

Music Control Methods:

USM.StopMusic(Audio.Music.BackGroundMusic);

// Pause/resume music
USM.PauseMusic(Audio.Music.BackGroundMusic);
USM.ResumeMusic(Audio.Music.BackGroundMusic);

// Set music volume
USM.SetMusicVolume(Audio.Music.BackGroundMusic,0.5f,1f); // 50% volume over 1 second

Advanced Audio Features

Audio Ducking (Automatic Volume Control)

// Enable auto-ducking (lowers music when SFX play)
USM.AutoDuckEnable(0.5f, 0.5f, 1.0f);
// Parameters: duck amount, fade in time, fade out time

// Manual ducking control
USM.DuckMusic(0.3f, 0.5f); // Duck to 30% volume over 0.5 seconds
USM.UnduckMusic(1.0f); // Return to normal over 1 second

// Check ducking status
bool isDucked = USM.IsMusicDucked();
bool autoDuckEnabled = USM.IsAutoDuckEnabled();

Global Volume Control

// Set volumes globally
USM.SetGlobalVolume(0.8f); // 80% master volume
USM.SetMusicVolume(0.6f);  // 60% music volume  
USM.SetSFXVolume(1.0f);    // 100% SFX volume

// These affect ALL sounds immediately

Audio State Management

// Stop all audio
USM.StopAll();

// Stop all sound effects only
USM.StopAllSFX();

// Stop all music only
USM.StopAllMusic(true, 2.0f); // With 2-second fade

// Check what's playing
bool isPlaying = USM.IsPlaying(Audio.Music.BackGroundMusic);
bool musicPlaying = USM.IsMusicPlaying();
string currentMusic = USM.GetCurrentMusicID();

Performance Optimization

Best Practices:

Pool Size Management:

  • Start with 20 audio sources

  • Monitor performance in complex scenes

  • Increase if you hear sounds cutting out

  • Don't exceed 50 unless absolutely necessary

Memory Management:

  • The Audio Manager automatically cleans up finished sounds

  • No manual memory management required

  • Audio sources are reused efficiently

CPU Optimization:

  • Spatial audio (3D sounds) use more CPU

  • Keep most UI sounds as 2D (spatial blend = 0)

  • Use audio compression on source files

  • Limit simultaneous complex audio effects

Last updated