The s&box audio system lets you play sounds from code usingDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/facepunch/sbox-public/llms.txt
Use this file to discover all available pages before exploring further.
Sound.Play(), attach looping or triggered sounds to GameObjects with SoundPointComponent and SoundBoxComponent, track and control playing sounds through SoundHandle, and organize output levels with Audio.Mixer. This page covers each of these APIs and how they fit together.
Quick start: playing a sound
The fastest way to play a sound from code isSound.Play(). Pass a SoundEvent asset name or a SoundEvent reference.
Sound.Play returns SoundHandle.Empty on a headless/dedicated server. Always check handle.IsValid if you intend to modify the handle after playing.SoundHandle
SoundHandle is a reference to a sound that is currently playing. Use it to update position, volume, pitch, or stop the sound.
Key SoundHandle properties
| Property | Type | Description |
|---|---|---|
Position | Vector3 | World-space position used for 3D spatialization. |
Volume | float | Playback volume. Range 0–1. |
Pitch | float | Playback pitch. 1.0 is normal speed. |
IsPlaying | bool | True while the sound has not been stopped. |
Paused | bool | Pause or resume playback without releasing the handle. |
Distance | float | Maximum audible distance in world units (default 15000). |
Falloff | Curve | Distance attenuation curve. |
DistanceAttenuation | bool | Whether volume falls off with distance. |
AirAbsorption | bool | High frequencies attenuate at distance. |
Occlusion | bool | Geometry occludes the sound. |
OcclusionRadius | float | Sphere radius for partial occlusion. |
Transmission | bool | Sound transmits through walls. |
ListenLocal | bool | When true, plays as a 2D (UI) sound ignoring position. |
SpacialBlend | float | 0 = fully 2D, 1 = fully 3D. |
TargetMixer | Mixer | Routes this sound to a specific mixer channel. |
Amplitude | float | Current loudness level — useful for lip-sync or VU meters. |
Time | float | Current playback position in seconds. Seek by assigning. |
Stopping with a fade
Preloading
Preload a sound event before it is needed to avoid a stutter on first play:SoundPointComponent
SoundPointComponent is a scene component that plays a sound at the GameObject’s world position. It updates the position every frame automatically, so attaching it to a moving object keeps the audio in sync.
Add it in the editor under Audio → Sound Point, or attach it in code:
Properties
| Property | Description |
|---|---|
SoundEvent | The sound event asset to play. |
PlayOnStart | Start playing automatically when the component is enabled. |
StopOnNew | Stop the current sound before playing a new one when StartSound() is called. |
Volume | Playback volume override (requires SoundOverride = true). |
Pitch | Playback pitch override (requires SoundOverride = true). |
Force2d | Ignore 3D position; play as a flat 2D sound. |
Repeat | Replay the sound after it finishes, with a random delay in [MinRepeatTime, MaxRepeatTime]. |
DistanceAttenuationOverride | Override the event’s attenuation settings with Distance and Falloff. |
OcclusionOverride | Override occlusion settings. |
TargetMixer | Route to a specific mixer channel. |
Triggering manually
Temporary effect
SoundPointComponent implements Component.ITemporaryEffect, so it can be used with pooled or short-lived GameObjects. The engine keeps the object alive until IsActive returns false (i.e., the sound finishes playing).
SoundBoxComponent
SoundBoxComponent plays a sound whose apparent position is always the closest point on a box volume to the listener. This makes ambient area sounds (caves, rooms, machinery) feel natural as the listener moves through the space.
SndPos) is recalculated each update by finding the nearest listener and clamping it to the box surface. You can read SndPos to visualize where the audio source appears to come from.
AudioListener
By default the active camera provides the listener position for 3D audio. Add anAudioListener component to a different GameObject to override this — useful for third-person cameras, splitscreen, or top-down games where hearing should follow the character rather than the camera.
Audio.Mixer
Mixers let you group sounds and control their collective volume, spatialization, and occlusion. The default mixer receives all sounds that do not specify a target. Child mixers feed into their parent, forming a tree.Accessing named mixers
Mixers are defined in the project’s audio settings. Retrieve them by name:Mixer properties
Monitoring output levels
Each mixer exposes anAudioMeter you can poll for the current loudness:
Stopping all sounds on a mixer
Routing sounds to a mixer from a component
AllBaseSoundComponent-derived components expose a TargetMixer property of type MixerHandle:
Master volume
The global volume convar is exposed asSound.MasterVolume. You can read it but generally should not override it — it respects the user’s system preferences.