Skip to content

Audio

Audio lives on World.Audio. You play a loaded sound asset and get back an AudioHandle you can use to stop or adjust the voice while it plays.

CAudioStream Shot = Asset.Load<CAudioStream>("/Game/Content/Audio/Shot");
World.Audio.Play2D(Shot);

Sounds are fire-and-forget: you only need the returned handle if you want to change or stop the sound afterward. The audio engine is process-global, so these calls work the same from any script.

A 2D sound plays at full volume regardless of position — use it for UI, music, and non-diegetic effects. A 3D sound is attenuated by distance from the listener, fading between MinDistance (full volume) and MaxDistance (silent).

// UI / music.
World.Audio.Play2D(Music, Volume: 0.6f, Loop: true);
// Positional gunshot that falls off between 2m and 40m.
World.Audio.PlayAtLocation(Shot, Transform.GetWorldLocation(), MinDistance: 2.0f, MaxDistance: 40.0f);
MethodEffect
Play2D(sound, volume, pitch, loop)Non-spatialized playback
PlayAtLocation(sound, location, volume, pitch, minDistance, maxDistance, loop)Spatialized 3D playback

Every parameter after the sound is optional (Volume 1, Pitch 1, Loop false, MinDistance 1, MaxDistance 50). A null or unloaded sound returns an invalid handle and plays nothing.

Keep the AudioHandle to drive the voice after it starts. Every control call is safe on a stale or invalid handle — it simply does nothing.

AudioHandle Engine = World.Audio.PlayAtLocation(Loop, Location, Loop: true);
// Later, as the car revs and moves:
World.Audio.SetPitch(Engine, 1.0f + Throttle);
World.Audio.SetPosition(Engine, Transform.GetWorldLocation());
// When it stops:
World.Audio.Stop(Engine, FadeOut: true);
MethodEffect
Stop(handle, fadeOut)Stop a voice (optionally letting its fade-out play)
StopAll()Stop every playing sound
SetVolume(handle, volume)Live volume (1 = full)
SetPitch(handle, pitch)Live pitch multiplier (1 = original)
SetLooping(handle, loop)Toggle looping on a running voice
SetPosition(handle, position)Move a spatialized voice (track a moving emitter)
SetMinMaxDistance(handle, min, max)Update 3D attenuation range

The AudioHandle fields.

FieldMeaning
Generation / IndexIdentify the voice in the audio engine
IsValidfalse if the sound failed to start (no data, or audio disabled)