BabylonJS/Babylon.js · error · Error

The value passed to [Scene.audioListenerRotationProvider] mu

Error message

The value passed to [Scene.audioListenerRotationProvider] must be a function that returns a Vector3

What it means

Scene.audioListenerRotationProvider overrides the listener orientation for spatial audio; its setter (registered with the AudioSceneComponent) validates that any non-null value is a function returning a Vector3. Passing a non-function value throws this error.

Source

Thrown at packages/dev/core/src/Audio/audioSceneComponent.pure.ts:531

    Object.defineProperty(Scene.prototype, "audioListenerRotationProvider", {
        get: function (this: Scene) {
            let compo = this._getComponent(SceneComponentConstants.NAME_AUDIO) as AudioSceneComponent;
            if (!compo) {
                compo = new AudioSceneComponent(this);
                this._addComponent(compo);
            }

            return compo.audioListenerRotationProvider;
        },
        set: function (this: Scene, value: () => Vector3) {
            let compo = this._getComponent(SceneComponentConstants.NAME_AUDIO) as AudioSceneComponent;
            if (!compo) {
                compo = new AudioSceneComponent(this);
                this._addComponent(compo);
            }

            if (value && typeof value !== "function") {
                throw new Error("The value passed to [Scene.audioListenerRotationProvider] must be a function that returns a Vector3");
            } else {
                compo.audioListenerRotationProvider = value;
            }
        },
        enumerable: true,
        configurable: true,
    });

    Object.defineProperty(Scene.prototype, "audioPositioningRefreshRate", {
        get: function (this: Scene) {
            let compo = this._getComponent(SceneComponentConstants.NAME_AUDIO) as AudioSceneComponent;
            if (!compo) {
                compo = new AudioSceneComponent(this);
                this._addComponent(compo);
            }

            return compo.audioPositioningRefreshRate;
        },

View on GitHub (pinned to 0592b347b8)

Solutions

  1. Assign a synchronous function returning a Vector3, e.g. () => camera.getDirection(Axis.Z)
  2. Wrap a static Vector3 in a function: () => myDirectionVector
  3. Do not return a Promise; compute the value synchronously
  4. Use null to reset to default listener rotation

Example fix

// before
scene.audioListenerRotationProvider = camera.rotation; // throws (not a function)
// after
scene.audioListenerRotationProvider = () => camera.getDirection(new Vector3(0, 0, 1));
Defensive patterns

Strategy: type-guard

Validate before calling

const provider = /* candidate */;
if (provider != null && typeof provider !== "function") {
    throw new Error("audioListenerRotationProvider must be a function returning Vector3");
}
scene.audioListenerRotationProvider = provider;

Type guard

const isListenerRotationProvider = (v: unknown): v is (() => Vector3) | null =>
    v == null || typeof v === "function";

Try / catch

try {
    scene.audioListenerRotationProvider = candidate;
} catch (e) {
    if (e.message.includes("audioListenerRotationProvider")) {
        scene.audioListenerRotationProvider = () => camera.getDirection(Axis.Z);
    }
}

Prevention

When it happens

Trigger: Assigning scene.audioListenerRotationProvider = <non-function> such as a Vector3, quaternion, or plain object when the audio scene component registers the property (on first audio usage).

Common situations: Passing a Quaternion or Euler object instead of a function returning a Vector3 direction; misunderstanding that rotation is expressed as a Vector3 (forward direction) from a function; async code returning a Promise<Vector3>.

Related errors


AI-assisted analysis of BabylonJS/Babylon.js@0592b347b8 (2026-08-30). Data as JSON: /api/errors/139cb85b6fc68cb4. Report an issue: GitHub.