{"record":{"id":"8cbb6ed7abd0ddd7","repo":"BabylonJS/Babylon.js","slug":"the-value-passed-to-scene-audiolistenerpositionpr","errorCode":null,"errorMessage":"The value passed to [Scene.audioListenerPositionProvider] must be a function that returns a Vector3","messagePattern":"The value passed to \\[Scene\\.audioListenerPositionProvider\\] must be a function that returns a Vector3","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/dev/core/src/Audio/audioSceneComponent.pure.ts","lineNumber":504,"sourceCode":"    Object.defineProperty(Scene.prototype, \"audioListenerPositionProvider\", {\r\n        get: function (this: Scene) {\r\n            let compo = this._getComponent(SceneComponentConstants.NAME_AUDIO) as AudioSceneComponent;\r\n            if (!compo) {\r\n                compo = new AudioSceneComponent(this);\r\n                this._addComponent(compo);\r\n            }\r\n\r\n            return compo.audioListenerPositionProvider;\r\n        },\r\n        set: function (this: Scene, value: () => Vector3) {\r\n            let compo = this._getComponent(SceneComponentConstants.NAME_AUDIO) as AudioSceneComponent;\r\n            if (!compo) {\r\n                compo = new AudioSceneComponent(this);\r\n                this._addComponent(compo);\r\n            }\r\n\r\n            if (value && typeof value !== \"function\") {\r\n                throw new Error(\"The value passed to [Scene.audioListenerPositionProvider] must be a function that returns a Vector3\");\r\n            } else {\r\n                compo.audioListenerPositionProvider = value;\r\n            }\r\n        },\r\n        enumerable: true,\r\n        configurable: true,\r\n    });\r\n\r\n    Object.defineProperty(Scene.prototype, \"audioListenerRotationProvider\", {\r\n        get: function (this: Scene) {\r\n            let compo = this._getComponent(SceneComponentConstants.NAME_AUDIO) as AudioSceneComponent;\r\n            if (!compo) {\r\n                compo = new AudioSceneComponent(this);\r\n                this._addComponent(compo);\r\n            }\r\n\r\n            return compo.audioListenerRotationProvider;\r\n        },\r","sourceCodeStart":486,"sourceCodeEnd":522,"githubUrl":"https://github.com/BabylonJS/Babylon.js/blob/0592b347b8a4ee0236089ea86a749cacfdb266d8/packages/dev/core/src/Audio/audioSceneComponent.pure.ts#L486-L522","documentation":"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.","triggerScenarios":"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).","commonSituations":"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).","solutions":["Assign a function that returns a Vector3: scene.audioListenerPositionProvider = () => new Vector3(...)","If you have a Vector3 value, wrap it: () => myVector3","Ensure the function returns a Vector3 synchronously, not a Promise","Only assign null/undefined (falsy) to clear the provider"],"exampleFix":"// before\nscene.audioListenerPositionProvider = new Vector3(0, 1, 0); // throws\n// after\nscene.audioListenerPositionProvider = () => new Vector3(0, 1, 0);","handlingStrategy":"type-guard","validationCode":"const provider = /* candidate */;\nif (provider !== null && provider !== undefined && typeof provider !== \"function\") {\n    throw new Error(\"audioListenerPositionProvider must be a function returning Vector3\");\n}\nscene.audioListenerPositionProvider = provider;","typeGuard":"const isListenerPositionProvider = (v: unknown): v is (() => Vector3) | null =>\n    v === null || v === undefined || (typeof v === \"function\");","tryCatchPattern":"try {\n    scene.audioListenerPositionProvider = candidate;\n} catch (e) {\n    if (e.message.includes(\"audioListenerPositionProvider\")) {\n        console.error(\"Provider must be () => Vector3, got:\", typeof candidate);\n    }\n}","preventionTips":["Remember providers are FUNCTIONS, not Vector3 values — wrap values in () => vec","Ensure the function returns Vector3 synchronously (no async/Promise)","Type the property explicitly in your wrapper API to catch errors at compile time"],"tags":["audio","webaudio","validation","types"],"backgroundTag":"callback-type-mismatch","analyzedSha":"0592b347b8a4ee0236089ea86a749cacfdb266d8","analyzedAt":"2026-08-30T15:11:20.442Z","schemaVersion":2},"datasetVersion":"2026-08-30T18:17:15.746Z"}