AudioSource
AudioSource controls a resident VAG clip assigned to an Audio Source component
on the target GameObject.
| Method | Returns | Description |
|---|---|---|
AudioSource.Play(gameObjectId) | boolean | Starts or restarts tracked playback. |
AudioSource.PlayOneShot(gameObjectId) | boolean | Starts an independent one-shot voice. |
AudioSource.Stop(gameObjectId) | boolean | Stops tracked playback. |
AudioSource.SetVolume(gameObjectId, volume) | boolean | Sets normalized volume. |
AudioSource.SetPan(gameObjectId, pan) | boolean | Sets stereo pan in -1.0..1.0. |
AudioSource.IsPlaying(gameObjectId) | boolean | Reads tracked playback state. |
function Start(gameObjectId)
AudioSource.SetVolume(gameObjectId, 0.8)
AudioSource.SetPan(gameObjectId, 0.0)
end
function Impact(gameObjectId)
if not AudioSource.PlayOneShot(gameObjectId) then
Log.Print("Impact voice unavailable")
end
end
Resident clips consume SPU RAM and runtime voices. Use Music for long CD-XA streams and Audio Import for conversion and budget rules.
Choose playback ownership
Use AudioSource.Play for a sound that must stop with its action, such as a door creak or a moving chest lid. AudioSource.Stop stops that source's tracked voice, and AudioSource.IsPlaying reports only that tracked playback. Calling Play again on the same source restarts it.
Use AudioSource.PlayOneShot for independent footsteps, UI cues or impacts. These voices can overlap; Stop and IsPlaying on the source do not control or report them. Do not start a one-shot every frame while a condition stays true. For UI navigation, compare the selected element with the previous selection and play only on change. For repeated knocks, schedule a bounded number of spaced events in Update; do not issue them all in one callback.
Check the boolean returned by playback calls. A missing source, an unavailable clip or exhausted voices can prevent a sound. Keep resident-clip count, sample memory and simultaneous voices separate: the engine supports 16 resident clips per scene and the SPU supplies 24 playback voices. See Budget Dashboard.