BabylonJS/Babylon.js · error · Error

The value passed to [Scene.audioListenerPositionProvider] mu

Error message

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

What it means

Scene exposes audioListenerPositionProvider as a settable property that lets apps override the listener position for spatial audio. The registered setter validates that any non-null value is a function returning a Vector3; passing anything else throws this error at assignment time.

Source

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

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

            return compo.audioListenerPositionProvider;
        },
        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.audioListenerPositionProvider] must be a function that returns a Vector3");
            } else {
                compo.audioListenerPositionProvider = value;
            }
        },
        enumerable: true,
        configurable: true,
    });

    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;
        },

View on GitHub (pinned to 0592b347b8)

Solutions

  1. Assign a function that returns a Vector3: scene.audioListenerPositionProvider = () => new Vector3(...)
  2. If you have a Vector3 value, wrap it: () => myVector3
  3. Ensure the function returns a Vector3 synchronously, not a Promise
  4. Only assign null/undefined (falsy) to clear the provider

Example fix

// before
scene.audioListenerPositionProvider = new Vector3(0, 1, 0); // throws
// after
scene.audioListenerPositionProvider = () => new Vector3(0, 1, 0);
Defensive patterns

Strategy: type-guard

Validate before calling

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

Type guard

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

Try / catch

try {
    scene.audioListenerPositionProvider = candidate;
} catch (e) {
    if (e.message.includes("audioListenerPositionProvider")) {
        console.error("Provider must be () => Vector3, got:", typeof candidate);
    }
}

Prevention

When it happens

Trigger: Setting scene.audioListenerPositionProvider = <non-function>, e.g. a Vector3 directly, a promise, or a string, right after the AudioSceneComponent is registered (first audio use or scene construction with audio).

Common situations: Confusing the provider (a function) with the value it returns; copying code that sets it to a Vector3; passing an async function expecting it to be awaited (must return Vector3 synchronously).

Related errors


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