Stopping a sound#
Use a Stop Instruction to end a looping sound or interrupt one before it finishes. The four Instructions select sounds by channel, resource, target, or ID:
| Instruction | Stops |
|---|---|
| Stop Audio in Channel | Everything playing on one channel. |
| Stop Audio Resource | Every sound currently playing a particular Audio Resource. |
| Stop Audio on Game Object | Every sound whose Has Target is that object. |
| Stop Audio ID | One specific sound, by the ID it was given when it started. |
All four take the same two fields:
| Field | Controls |
|---|---|
| Transition | Seconds to fade out before stopping. Default 3. 0 cuts immediately. The fade runs in real time. |
| Await | Whether the Event waits for the fade before running the next Instruction. |
Which one to reach for#
Use Stop Audio Resource for a loop when only one copy of its resource should be playing. The Events that start and stop a rain loop can point at the same resource without storing an ID.
Use Stop Audio on Game Object for sounds associated with a character or other object. It stops the character's current voice without tracking the line, provided playback started with Has Target enabled. See Has Target.
Use Stop Audio in Channel when every sound in a category should end. For a scene transition, fade Ambient and Sound Effect while leaving Music active across the load.
Use a fade for gradual transitions
Transition defaults to 3 seconds. Keep a fade when moving between ambient zones or ending a music track gradually.
Set it to 0 when the sound should stop abruptly, such as a machine losing power.
Await#
With Await off, the Instruction starts the fade and the Event moves on immediately. With it on, the Event waits for the sound to finish fading before continuing.
Enable Await when the next action depends on silence, such as loading a scene after its music fades out. Leave it off when the Event should continue during the fade.
Asking what's playing#
Three Conditions check whether sounds selected by resource, target, or ID are playing:
| Condition | Asks |
|---|---|
| Is Playing Audio Resource | Is any sound playing this resource right now? |
| Is Playing on Game Object | Is any sound targeting this object right now? |
| Is Playing Audio ID | Is this specific sound still active? |
Use Is Playing Audio Resource as a guard when a loop must have only one active copy. Otherwise, repeatedly entering its trigger volume stacks another copy of the cue.
Playing the same clip twice plays it twice
The Audio Manager doesn't merge repeated requests. Two Play Instructions using the same resource produce two sounds, which may sound distorted if they play slightly out of phase.
Guard the Event with Is Playing Audio Resource, or start the loop from something that can only happen once.
Audio IDs#
Every sound receives a unique ID when it starts. Stop Audio ID and Is Playing Audio ID use that value to address one sound when several copies of a resource are active.
To keep an ID, point the Play Instruction's Save ID field at a String variable. The Instruction writes the new sound's ID there when it starts, and Stop Audio ID and Is Playing Audio ID can then read the same variable.
Each torch stops its own crackle
- Each torch's Event plays its crackle loop with Save ID set to a local String variable named
crackle-id. - When the torch goes out, Stop Audio ID reads
crackle-idand fades that sound out.
The other torches play the same resource, but each keeps its own ID, so only the extinguished torch falls silent.
Prefer selecting sounds by resource, channel, or target when that's specific enough. Use an ID when you need to select one instance among several matching sounds. In C#, AudioManager.Play returns the same ID. See the Audio API.
An empty or invalid ID is ignored
When the String isn't a valid ID, such as a variable that no sound has written yet, Stop Audio ID does nothing and Is Playing Audio ID returns false. If a stop seems to have no effect, check that the Play Instruction's Save ID writes to the same variable.
Where to go next#
- Playing a sound — assign Has Target and configure how a sound starts.
- Channels — understand what Stop Audio in Channel selects.
- Audio API — obtain and use audio IDs from
AudioManager.