Audio Collections
Playback methods for grouped sounds registered in the Audio Manager.
What is an Audio Collection?
An AudioCollection is a container that manages multiple audio clips as a group — footstep variants, UI sound packs, ambient loops, character voice lines, and other related sounds you want to organize together.
Each collection holds multiple clips and provides methods for playing a specific sound by name or triggering a random entry from the group. Calling a method on one collection only affects sounds within that collection.
Creating an Audio Collection
You need an AudioCollection reference before calling any playback method. There are two ways to get one:
Inspector assignment
Declare a field on your script and assign the collection from the Unity Inspector. See Inspector Assignment for the full walkthrough.
Get function
Look up the collection by name at runtime with GetAudioCollection. This is useful when the collection name comes from data or the same script handles multiple entities. See Get Functions for details on all lookup methods.
API Reference
Once you have a reference, use the methods below to control playback. Pass the exact sound name shown in the Audio Manager window — names are case-sensitive.
Play
Plays a specific sound from the collection using the default volume and pitch you set for that sound in the Audio Manager window. Restarts from the beginning if the sound is already playing.
Play (soundName, volume, pitch)
Plays a named sound with explicit volume and pitch values. volume is typically between 0f (silent) and 1f (full). pitch uses 1f as the normal playback speed — lower values sound deeper and slower, higher values sound sharper and faster.
Example
PlayRandomPitch
Plays a named sound once with a pitch randomly chosen between minPitch and maxPitch on each call. This adds natural variation so repeated sounds — footsteps, gunfire, UI taps — feel less mechanical without needing separate clips.
Example
Stop
Stops playback of a specific sound in the collection. Other sounds in the same collection that are currently playing are not affected.
PlayRandomAudio
Plays a random sound from the entire collection using each clip's default volume and pitch from the Audio Manager window. Use this when you want variety without picking a specific sound name — ambient one-shots, randomized impact effects, or surprise voice lines.
Common Use Cases
For practical examples — footstep groups, UI packs, ambient variety, and more — see the Common Use Cases page.