Search documentation

Search documentation pages and sections

Get it

Audio Collections — Common Use Cases

Practical examples for playing, varying, and managing grouped sounds.

Overview

AudioCollection works best when you have multiple related clips organized together — footstep sets, UI packs, ambient libraries, or voice banks. You address sounds by name or let the collection pick one at random.

Sound names must match exactly what appears in the Audio Manager window. For method signatures and parameter details, see the API Reference.

Footstep Variants

Store all footstep clips in one collection and play a named entry with random pitch on each step. This keeps surface variants organized in the Audio Manager while the gameplay code stays a single line.

Example

C#
public AudioCollection footstepSounds;

void OnFootstep()
{
    footstepSounds.PlayRandomPitch("Footstep", 0.9f, 1.1f);
}

If you need a dedicated reference to one footstep clip instead of passing a name each time, use SoundFromGroup — see the Sound from Group common use cases.

UI Sound Pack

Group every menu sound — confirm, cancel, error, hover — into one collection. Call Play with the sound name that matches the action. Override volume or pitch for individual events when needed.

Example

C#
public AudioCollection uiSounds;

public void OnConfirm()
{
    uiSounds.Play("Confirm");
}

public void OnCancel()
{
    uiSounds.Play("Cancel");
}

public void OnError()
{
    uiSounds.Play("Error", 0.8f, 1f);
}

Ambient Variety

Forest birds, cave drips, city traffic — ambient one-shots feel more natural when they are not always the same clip. PlayRandomAudiopicks any entry from the collection using each clip's default settings, so you get variety without choosing a name in code.

Example

C#
public AudioCollection forestAmbience;

void PlayAmbientOneShot()
{
    forestAmbience.PlayRandomAudio();
}

Character Voice Lines

Keep all lines for a character in one collection and trigger them by name from dialogue or quest scripts. Each line stays editable in the Audio Manager without touching gameplay code.

Example

C#
public AudioCollection characterVoices;

void OnGreeting()
{
    characterVoices.Play("Greeting");
}

void OnQuestComplete()
{
    characterVoices.Play("QuestComplete");
}

Stopping a Specific Sound

Collections can have multiple sounds playing at once. When switching music states, stop only the track that is currently active — other sounds in the same collection keep playing.

Example

C#
public AudioCollection musicTracks;

void SwitchToCombatMusic()
{
    musicTracks.Stop("Exploration");
    musicTracks.Play("Combat");
}