Skip to content

Audio Source

Plays an audio clip from the entity's position.

The clip gets quieter as the Audio Listener moves away from it. It's at full volume within MinDistance, and stops getting quieter beyond MaxDistance. Set Stream for long clips such as music, so they're read from disk as they play instead of being decoded all at once.

Scene file

Saved as a <AudioSource> element inside the entity's <Entity> element. Attributes that are left out keep their default. See Scene Files for how values like vectors, colours and file paths are written.

<AudioSource Filepath="Audio/Music.mp3" Volume="0.8" Pitch="1" Loop="true"
             MinDistance="1" MaxDistance="10" Rolloff="1" Stream="true" PlayOnStart="true"/>
Name Where Type Default
Filepath attribute: project-relative path path to an audio file none
Volume attribute float 1
Pitch attribute float 1
Loop attribute bool false
MinDistance / MaxDistance attributes float, world units 1 / 10
Rolloff attribute float 1
Stream attribute bool false
PlayOnStart attribute bool, start playing when the game starts false

Lua scripting

Properties

  • Clip (AudioClip): The audio clip to play
  • Loop (boolean): Restart the clip when it finishes
  • MaxDistance (number): Distance from the listener beyond which the clip stops getting quieter
  • MinDistance (number): Distance from the listener within which the clip plays at full volume
  • Pitch (number): Playback speed and pitch multiplier
  • Rolloff (number): How quickly the volume falls off between MinDistance and MaxDistance
  • Stream (boolean): Stream the clip from disk instead of decoding it all up front
  • Volume (number): Volume multiplier, 1 being the clip's own volume

Functions

  • Pause(): Pause playback
  • Play(): Start or resume playback
  • Stop(): Stop playback and rewind to the start