menu_bookDocumentation

Playing Sounds: SoundEvent, SoundHandle, and GameObject Audio in s&box

calendar_today May 20, 2026 schedule ~1 min read person PatrickJr verified 50

s&box provides several ways to play sounds in code: fire-and-forget at a world position, control via SoundHandle, attach to a GameObject, or use scene components.

SoundEvent Assets

Most sounds are defined as SoundEvent assets (.sound files) bundling audio files with volume, pitch, 3D distance, and occlusion settings.

CSHARP
[Property] public SoundEvent FootstepSound { get; set; }
var sound = ResourceLibrary.Get<SoundEvent>( "sounds/footsteps/concrete.sound" );

Sound.Play

Primary static API returning a SoundHandle:

CSHARP
Sound.Play( FootstepSound );
Sound.Play( "sounds/explosion.sound" );
Sound.Play( ExplosionSound, WorldPosition ); // 3D positional
Sound.Play( AmbientSound, WorldPosition, fadeInTime: 2.0f ); // fade in

SoundHandle Properties

PropertyDescription
PositionWorld-space position
VolumeVolume multiplier (default 1.0)
PitchPitch multiplier (default 1.0, 2.0 = one octave up)
DistanceMax audible distance (default 15000)
SpacialBlend0 = 2D, 1 = 3D (default 1.0)
OcclusionWhether geometry blocks the sound
PausedPause/resume without stopping
CSHARP
SoundHandle _engine = Sound.Play( EngineLoop, WorldPosition );
_engine.Volume = 0.8f;
_engine.Pitch = 1.2f;
_engine.Stop( 1.5f ); // fade out

GameObject.PlaySound

Plays a sound that follows the GameObject's position every frame:

CSHARP
var handle = GameObject.PlaySound( FootstepSound );
var handle = GameObject.PlaySound( FootstepSound, Vector3.Up * 64f ); // local offset
GameObject.StopAllSounds( fadeOutTime: 0.5f );

Audio Components

ComponentDescription
SoundPointComponentPlays at a fixed world point with auto-play and looping
SoundBoxComponentSource position constrained to a box region
SoundscapeTriggerBlends ambient soundscape when listener enters trigger
AudioListenerOverrides listening position (default is camera)
Was this helpful?