{"record":{"id":"0f309adc8c34e18a","repo":"BabylonJS/Babylon.js","slug":"anchors-not-enabled-in-this-environment-browser","errorCode":null,"errorMessage":"Anchors not enabled in this environment/browser","messagePattern":"Anchors not enabled in this environment/browser","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/dev/core/src/XR/features/WebXRAnchorSystem.pure.ts","lineNumber":215,"sourceCode":"     * @param position an optional position offset for this anchor\r\n     * @param rotationQuaternion an optional rotation offset for this anchor\r\n     * @returns A promise that fulfills when babylon has created the corresponding WebXRAnchor object and tracking has begun\r\n     */\r\n    public async addAnchorPointUsingHitTestResultAsync(\r\n        hitTestResult: IWebXRHitResult,\r\n        position: Vector3 = new Vector3(),\r\n        rotationQuaternion: Quaternion = new Quaternion()\r\n    ): Promise<IWebXRAnchor> {\r\n        // convert to XR space (right handed) if needed\r\n        this._populateTmpTransformation(position, rotationQuaternion);\r\n        // the matrix that we'll use\r\n        const m = new XRRigidTransform(\r\n            { x: this._tmpVector.x, y: this._tmpVector.y, z: this._tmpVector.z },\r\n            { x: this._tmpQuaternion.x, y: this._tmpQuaternion.y, z: this._tmpQuaternion.z, w: this._tmpQuaternion.w }\r\n        );\r\n        if (!hitTestResult.xrHitResult.createAnchor) {\r\n            this.detach();\r\n            throw new Error(\"Anchors not enabled in this environment/browser\");\r\n        } else {\r\n            try {\r\n                const nativeAnchor = await hitTestResult.xrHitResult.createAnchor(m);\r\n                return await new Promise<IWebXRAnchor>((resolve, reject) => {\r\n                    this._futureAnchors.push({\r\n                        nativeAnchor,\r\n                        resolved: false,\r\n                        submitted: true,\r\n                        xrTransformation: m,\r\n                        resolve,\r\n                        reject,\r\n                    });\r\n                });\r\n            } catch (error) {\r\n                throw new Error(String(error), { cause: error });\r\n            }\r\n        }\r\n    }\r","sourceCodeStart":197,"sourceCodeEnd":233,"githubUrl":"https://github.com/BabylonJS/Babylon.js/blob/0592b347b8a4ee0236089ea86a749cacfdb266d8/packages/dev/core/src/XR/features/WebXRAnchorSystem.pure.ts#L197-L233","documentation":"WebXRAnchorSystem.addAnchorPointUsingHitTestResultAsync tries to create an anchor from an XRHitTestResult via the createAnchor method. The WebXR anchors module is optional: some browsers/environments do not expose createAnchor on hit test results. The system detects this, detaches, and throws to signal that anchor creation is impossible in the current runtime.","triggerScenarios":"Calling addAnchorPointUsingHitTestResultAsync(hitTestResult) when hitTestResult.xrHitResult.createAnchor is undefined — i.e. the XRHitTestResult came from a session/environment without the 'anchors' feature enabled.","commonSituations":"Running on browsers without WebXR anchors module support, requesting hit test without the 'anchors' optional feature in the session's optionalFeatures list, testing in the WebXR emulator or older headset browsers.","solutions":["Add 'anchors' to requiredFeatures or optionalFeatures when creating the WebXR session","Check support via WebXRAnchorSystem.IsSupportedAsync or the native createAnchor presence before calling","Update the browser/headset firmware to a version with WebXR anchors support","Fall back to a manual tracking object (e.g. TransformNode updated by hit test pose) when anchors are unavailable"],"exampleFix":"// before\nconst anchor = await anchorSystem.addAnchorPointUsingHitTestResultAsync(hitTestResult);\n// after\nif (hitTestResult.xrHitResult.createAnchor) {\n  const anchor = await anchorSystem.addAnchorPointUsingHitTestResultAsync(hitTestResult);\n} else {\n  console.warn('anchors unavailable; using plain transform');\n}","handlingStrategy":"type-guard","validationCode":"const anchorsOk = hitTestResult.xrHitResult && typeof hitTestResult.xrHitResult.createAnchor === 'function';","typeGuard":"function canCreateAnchor(hit: { xrHitResult: XRHitTestResult }): hit is { xrHitResult: XRHitTestResult & { createAnchor(t: XRRigidTransform): Promise<XRAnchor> } } {\n  return typeof hit.xrHitResult.createAnchor === 'function';\n}","tryCatchPattern":"try {\n  const anchor = await anchorSystem.addAnchorPointUsingHitTestResultAsync(hitTestResult);\n} catch (e) {\n  console.warn('anchor creation unavailable; falling back to transform node');\n}","preventionTips":["Add 'anchors' to requiredFeatures/optionalFeatures of the session","Check WebXRAnchorSystem.IsSupportedAsync before using anchors","Keep a non-anchor fallback for unsupported devices","Test on target headsets early"],"tags":["webxr","anchors","feature-detection"],"backgroundTag":"missing-browser-api","analyzedSha":"0592b347b8a4ee0236089ea86a749cacfdb266d8","analyzedAt":"2026-08-30T15:11:20.442Z","schemaVersion":2},"datasetVersion":"2026-08-30T18:17:15.746Z"}