Skip to content

Audio

Updated

Plays a sound heard the same everywhere, for music or UI.

Type
comp-audio
Script class
AudioComponent
Per entity
One
Version
1.0.0

Read about it in Audio sources: what it does, how to use it from a script, and examples.

The props the runtime declares for this component, with their defaults and accepted ranges.

Prop Default Range
volume 0 ≤ x ≤ 1

Sent to the entity’s Signal Emitter as { entityId, eventType, data }. Compare eventType with the EventType constants.

  • Audio::ready
  • Audio::error
  • Audio::play
  • Audio::pause
  • Audio::stop
  • Audio::end

Run it in the browser, read its scripts, and download it as an XR Creator project.

#pragma lifecycle(startup)
function startup() {
const component = self.parent.getComponent(AudioComponent);
if (component) log(component.props);
}