BabylonJS/Babylon.js · error

Anchors not enabled in this environment/browser

Error message

Anchors not enabled in this environment/browser

What it means

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.

Source

Thrown at packages/dev/core/src/XR/features/WebXRAnchorSystem.pure.ts:215

     * @param position an optional position offset for this anchor
     * @param rotationQuaternion an optional rotation offset for this anchor
     * @returns A promise that fulfills when babylon has created the corresponding WebXRAnchor object and tracking has begun
     */
    public async addAnchorPointUsingHitTestResultAsync(
        hitTestResult: IWebXRHitResult,
        position: Vector3 = new Vector3(),
        rotationQuaternion: Quaternion = new Quaternion()
    ): Promise<IWebXRAnchor> {
        // convert to XR space (right handed) if needed
        this._populateTmpTransformation(position, rotationQuaternion);
        // the matrix that we'll use
        const m = new XRRigidTransform(
            { x: this._tmpVector.x, y: this._tmpVector.y, z: this._tmpVector.z },
            { x: this._tmpQuaternion.x, y: this._tmpQuaternion.y, z: this._tmpQuaternion.z, w: this._tmpQuaternion.w }
        );
        if (!hitTestResult.xrHitResult.createAnchor) {
            this.detach();
            throw new Error("Anchors not enabled in this environment/browser");
        } else {
            try {
                const nativeAnchor = await hitTestResult.xrHitResult.createAnchor(m);
                return await new Promise<IWebXRAnchor>((resolve, reject) => {
                    this._futureAnchors.push({
                        nativeAnchor,
                        resolved: false,
                        submitted: true,
                        xrTransformation: m,
                        resolve,
                        reject,
                    });
                });
            } catch (error) {
                throw new Error(String(error), { cause: error });
            }
        }
    }

View on GitHub (pinned to 0592b347b8)

Solutions

  1. Add 'anchors' to requiredFeatures or optionalFeatures when creating the WebXR session
  2. Check support via WebXRAnchorSystem.IsSupportedAsync or the native createAnchor presence before calling
  3. Update the browser/headset firmware to a version with WebXR anchors support
  4. Fall back to a manual tracking object (e.g. TransformNode updated by hit test pose) when anchors are unavailable

Example fix

// before
const anchor = await anchorSystem.addAnchorPointUsingHitTestResultAsync(hitTestResult);
// after
if (hitTestResult.xrHitResult.createAnchor) {
  const anchor = await anchorSystem.addAnchorPointUsingHitTestResultAsync(hitTestResult);
} else {
  console.warn('anchors unavailable; using plain transform');
}
Defensive patterns

Strategy: type-guard

Validate before calling

const anchorsOk = hitTestResult.xrHitResult && typeof hitTestResult.xrHitResult.createAnchor === 'function';

Type guard

function canCreateAnchor(hit: { xrHitResult: XRHitTestResult }): hit is { xrHitResult: XRHitTestResult & { createAnchor(t: XRRigidTransform): Promise<XRAnchor> } } {
  return typeof hit.xrHitResult.createAnchor === 'function';
}

Try / catch

try {
  const anchor = await anchorSystem.addAnchorPointUsingHitTestResultAsync(hitTestResult);
} catch (e) {
  console.warn('anchor creation unavailable; falling back to transform node');
}

Prevention

When it happens

Trigger: Calling addAnchorPointUsingHitTestResultAsync(hitTestResult) when hitTestResult.xrHitResult.createAnchor is undefined — i.e. the XRHitTestResult came from a session/environment without the 'anchors' feature enabled.

Common situations: 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.

Related errors


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