S&box Wiki

Guide to Sounds

A beginners guide to sounds

This guide assumes you've already created a sound or imported a sound.

Adjustable Properties

In the inspector, you can adjust values like volume, pitch, and decibels. If your sound is supposed to be a screen sound, you will also need to select the UI option.

From here, you can also upload the sound to asset.party.


Saving this file via ctrl + s or clicking on Full Recompile will compile both the source sound and the sound event.


Looping Sounds

For looping sounds you will have to either:

  • Place loop markers inside your sound file
  • Left-click the source sound in the assets browser and select the loop checkbox in the inspector. This will only work with .wav and .mp3 files.

Playing a Sound from Code

To play the sound in-game, you should use one of the static methods from the Sound class, using the name of the .sound asset type without the extension:

public override void Spawn() { // Plays the sound from an entity's position Sound.FromEntity("atm_card.insert", this); // Plays the sound from a position in the world Sound.FromWorld("atm_card.insert", new Vector3(0, 0, 0)); // Plays the sound from a position on your screen, useful for UI interactions // Make sure your .sound file has "2D" enabled Sound.FromScreen("atm_card.insert"); }
Sounds can be predicted - if you're playing a sound in a predicted method such as Simulate you should make sure your logic is predictable, if it isn't you should appropriately wrap it with Prediction.Off otherwise you will hear nothing.