Audio Zone
Updated
Inside the box, only sounds in the same zone are heard.
- Type
comp-audio-zone- Script class
AudioZoneComponent- Per entity
- One
- Version
- 1.0.0
Read about it in Spatial audio: what it does, how to use it from a script, and examples.
Properties
Section titled “Properties”The props the runtime declares for this component, with their defaults and accepted ranges.
| Prop | Default | Range |
|---|---|---|
halfExtents.x |
0 ≤ x ≤ 10000 |
|
halfExtents.y |
0 ≤ x ≤ 10000 |
|
halfExtents.z |
0 ≤ x ≤ 10000 |
Events
Section titled “Events”Sent to the entity’s Signal Emitter as { entityId, eventType, data }. Compare eventType with the EventType constants.
AudioZone::enterAudioZone::exit
Live example
Section titled “Live example”Run it in the browser, read its scripts, and download it as an XR Creator project.
Two Audio Zones, a library with rain on its windows and a workshop with a drum loop: their enter and exit events name the room in a HUD label and lower the hall music.
With your sound on, hold A for half a second to walk into the library, or D to walk into the workshop. Inside a room you hear only its own sound, and the label names it. The rain and the beat are short loops generated for this example.
From a script
Section titled “From a script”#pragma lifecycle(startup)
function startup() { const component = self.parent.getComponent(AudioZoneComponent); if (component) log(component.props);}