Skip to content

AudioSystem

Reconciles AudioComponent state with the underlying THREE.js positional audio objects each frame. Only active in preview mode — editor viewports are unaffected.

Overview

AudioSystem runs every frame in preview and is responsible for:

  • Driving play(), pause(), and stop() on the THREE.js PositionalAudio node based on the intent flags set by AudioComponent.play(), .pause(), and .stop().
  • Detecting when a non-looping clip ends naturally (THREE.js stops on its own) and resetting component state accordingly.
  • Syncing loop, pitch, volume, refDistance, distanceModel, and rolloffFactor to the live audio node whenever they change. Changes take effect on the next frame.

Queried components

ComponentAccess
AudioComponentRead + mutate (isPlaying, isPaused flags; option properties)

Behavior notes

  • Editor skip — when constructed with { isEditor: true } the update method returns immediately, so no audio state is applied in the editor.
  • Natural end detection — the system compares the THREE.js isPlaying state between frames. If the audio node stopped on its own while the component still believed it was playing (and not paused), the component flags are reset and a warning is suppressed.
  • Change detection — option sync uses a per-entity snapshot from the previous frame, so AudioComponent options can be mutated freely in scripts without causing redundant THREE.js calls on every frame.

API reference