codeAPI Reference

s&box SoundDefinition: Categorized sound GameResource

calendar_today May 12, 2026 schedule ~2 min read person PatrickJr verified 50

SoundDefinition GameResource API Reference

SoundDefinition is a GameResource that defines a categorized sound for use on spawned entities (thrusters, hoverballs, emitters, etc.). The Category field allows the editor to filter definitions by type.

Type Signature

CSHARP
[AssetType(Name = "Sound Definition", Extension = "sndef", Category = "Sandbox")]
public class SoundDefinition : GameResource, IDefinitionResource, IResourcePreview
{
    public const string Thruster = "thruster";
    public const string Hoverball = "hoverball";
    public const string Emitter = "emitter";

    [Property] public string Title { get; set; }
    [Property] public string Description { get; set; }
    [Property] public string Category { get; set; }
    [Property] public SoundEvent Sound { get; set; }

    public SoundHandle Play(Vector3 position);
    public SoundHandle Play(Vector3 position, GameObject parent);
    protected override Bitmap CreateAssetTypeIcon(int width, int height);
    public void OnPreview();
    public void OnPreviewStop();
}

Constants

Properties

Methods

Play(Vector3 position)

Plays the sound at the given world position. Returns default if no sound is set.

Play(Vector3 position, GameObject parent)

Plays the sound at the given world position, parented to a GameObject. Returns default if no sound is set. The sound will follow the parent.

OnPreview()

Implements IResourcePreview. Plays the sound for preview in the editor.

OnPreviewStop()

Implements IResourcePreview. Stops the preview sound.

Usage

Create an .sndef file to define a sound:

CSHARP
[AssetType(Name = "Sound Definition", Extension = "sndef", Category = "Sandbox")]
public class ThrusterSound : SoundDefinition
{
    [Property]
    public string Title { get; set; } = "Thruster Hum";

    [Property]
    public string Category { get; set; } = SoundDefinition.Thruster;

    [Property]
    public SoundEvent Sound { get; set; }
}

Play the sound in code:

CSHARP
var soundDef = Resource.GetFile<SoundDefinition>("sounds/my_thruster.sndef");
soundDef?.Play(thruster.WorldPosition, thruster.GameObject);

Notes

  • File extension is .sndef
  • Implements IDefinitionResource for metadata
  • Implements IResourcePreview for editor preview
  • Category property enables filtering in resource picker
  • Play() with parent enables following the GameObject
  • Used by thrusters, hoverballs, emitters, and other sound-emitting entities
Was this helpful?