menu_bookDocumentation

Playing Sounds: SoundHandle, GameObject.PlaySound, and Audio Components

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

s&box provides several ways to play sounds: fire-and-forget at a position, controlled via SoundHandle, attached to a GameObject, or via scene components.

SoundEvent Assets

Sounds are defined as .sound files bundling audio with settings (volume range, pitch range, 3D distance, occlusion). Reference from a component:

CSHARP
[Property] public SoundEvent FootstepSound { get; set; }

Or load at runtime:

CSHARP
var sound = ResourceLibrary.Get<SoundEvent>( "sounds/footsteps/concrete.sound" );

Sound.Play (Static API)

CSHARP
// By reference or path
Sound.Play( FootstepSound );
Sound.Play( "sounds/explosion.sound" );

// 3D positional
Sound.Play( ExplosionSound, WorldPosition );

// With fade in
Sound.Play( AmbientSound, WorldPosition, fadeInTime: 2.0f );

SoundHandle Control

Every Sound.Play returns a SoundHandle:

CSHARP
SoundHandle _engineLoop;

void StartEngine()
{
    _engineLoop = Sound.Play( EngineLoopSound, WorldPosition );
    _engineLoop.Volume = 0.8f;
    _engineLoop.Pitch = 1.2f;
}

// Stop with optional fade
_engineLoop.Stop( 1.5f );

// Stop all sounds
Sound.StopAll( fade: 0.5f );

Key properties: Position, Volume, Pitch, Distance, SpacialBlend (0=2D, 1=3D), Occlusion, IsPlaying, Paused, Time, TargetMixer.

GameObject.PlaySound (Following Sounds)

Plays a sound that follows the GameObject's position — recommended for moving objects:

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

GameObject.StopAllSounds( fadeOutTime: 0.5f );

Internally sets SoundHandle.Parent and FollowParent = true.

Audio Components

ComponentDescription
SoundPointComponentFixed world point, auto-play, looping
SoundBoxComponentSource constrained to a box region
SoundscapeTriggerAmbient soundscape on listener enter
AudioListenerOverrides listening position (default is camera)
Was this helpful?