Search documentation

Search documentation pages and sections

Get it

Sound from Group — Common Use Cases

Practical examples for targeting one specific sound inside a collection.

Overview

SoundFromGroup gives you a direct reference to a single entry inside an AudioCollection. Use it when you always play the same named clip and want cleaner code than passing a string on every call.

The playback API matches SingleSound Play, fades, pause, and resume work the same way. For method signatures, see the API Reference.

Named UI Click

UI sounds often live in a shared collection for organization. When one button always uses the same clip, wire up a SoundFromGroup reference instead of holding the whole collection and passing a name string.

Example

C#
public SoundFromGroup confirmClick;

public void OnConfirmPressed()
{
    confirmClick.Play();
}

Music Track from Collection

Store all level music in one collection but reference each track individually. Fade a specific theme in when exploration starts and fade it out when combat begins — other tracks in the collection are unaffected.

Example

C#
public SoundFromGroup explorationTheme;

void StartExploration()
{
    explorationTheme.FadeIn(2f, 0.6f);
}

void EnterCombat()
{
    explorationTheme.FadeOut(1f);
}

Voice Line

Attach a voice line directly to the NPC or quest object that triggers it. The clip stays grouped with the character's other lines in the Audio Manager, but the script only needs one field.

Example

C#
public SoundFromGroup questCompleteLine;

void OnQuestFinished()
{
    questCompleteLine.Play();
}

Runtime Lookup

When the target sound depends on runtime data — weapon class, character ID, item type — resolve it with GetSoundFromGroup and play immediately. You get the same direct API as an Inspector-assigned reference.

Example

C#
void PlayWeaponSound(string weaponId)
{
    SoundFromGroup weaponSound = AudioSystem.GetSoundFromGroup("Weapons", weaponId);
    weaponSound.Play();
}

See Get Functions for details on all runtime lookup methods.