BabylonJS/Babylon.js · error

BabylonScenePathToObjectConverter: invalid uniqueId "${parts

Error message

BabylonScenePathToObjectConverter: invalid uniqueId "${parts[1]}" in path "${path}".

What it means

Instance ids must be all-digit strings: the converter deliberately rejects parseInt-style leniency (which would accept "12abc" as 12) so a malformed path fails loudly instead of binding to the wrong instance. Any second segment that is not ^\d+$ throws this error. A finite, non-negative check follows, but non-numeric input is caught by the regex.

Source

Thrown at packages/dev/loaders/src/glTF/2.0/Extensions/babylonScenePathToObjectConverter.ts:158

        const collection = (this._tree as unknown as Record<string, IBabylonObjectCollection<any> | undefined>)[collectionName];
        if (!collection) {
            throw new Error(`BabylonScenePathToObjectConverter: unknown collection "${collectionName}" in path "${path}".`);
        }

        // Handle `<collection>.length` (no instance lookup).
        if (parts.length === 2 && parts[1] === "length") {
            const arr = this._getCollectionArray(collectionName);
            return { object: arr, info: collection.length as AnyAccessor };
        }

        if (parts.length < 2) {
            throw new Error(`BabylonScenePathToObjectConverter: path "${path}" is missing an instance id.`);
        }

        // parseInt would accept "12abc" as 12; require an all-digits id so a malformed path fails
        // loudly instead of binding to the wrong instance.
        if (!/^\d+$/.test(parts[1])) {
            throw new Error(`BabylonScenePathToObjectConverter: invalid uniqueId "${parts[1]}" in path "${path}".`);
        }
        const uniqueId = parseInt(parts[1], 10);
        if (!Number.isFinite(uniqueId) || uniqueId < 0) {
            throw new Error(`BabylonScenePathToObjectConverter: invalid uniqueId "${parts[1]}" in path "${path}".`);
        }

        const instance = this._lookupInstanceByUniqueId(collectionName, uniqueId);
        if (!instance) {
            throw new Error(`BabylonScenePathToObjectConverter: no ${collectionName} instance found with uniqueId ${uniqueId} (path "${path}").`);
        }

        // No property after the id → the ref itself is just a handle to the instance.
        // The accessor's `get` and `getTarget` both return the instance.
        if (parts.length === 2) {
            return {
                object: instance,
                info: this._buildIdentityAccessor(instance),
            };

View on GitHub (pinned to 0592b347b8)

Solutions

  1. Pass the Babylon object's numeric uniqueId (instance.uniqueId) as a plain digit string, not a name or glTF index.
  2. Sanitize/validate the id with /^\d+$/.test(id) before building the path; strip any non-digit suffixes introduced by string building.
  3. If you only have a glTF node index, resolve it to the Babylon instance first (via the loader's node mapping) and use its uniqueId.

Example fix

// before
converter.convert(`${prefix}transformNodes/${node.name}/position`); // name, not id
// after
converter.convert(`${prefix}transformNodes/${node.uniqueId}/position`);
Defensive patterns

Strategy: validation

Validate before calling

const id = String(instance.uniqueId);
if (!/^\d+$/.test(id)) {
  throw new Error(`uniqueId must be all digits, got: ${id}`);
}
converter.convert(`${BABYLON_SCENE_OBJECT_MODEL_PREFIX}transformNodes/${id}/position`);

Type guard

function isValidUniqueIdSegment(id: string): id is string {
  return /^\d+$/.test(id);
}

Try / catch

try {
  const info = converter.convert(path);
} catch (e) {
  // non-numeric id segment; re-derive path from instance.uniqueId
}

Prevention

When it happens

Trigger: convert() called with a non-numeric id segment such as ".../transformNodes/abc/position", ".../transformNodes/12abc", an empty-but-present segment, a name-based id, or a negative number like "-3".

Common situations: Using a node name or glTF node index string where a Babylon uniqueId is required; ids polluted by suffixes from templating; passing a UUID or stringified object key; locales/formatters injecting separators (e.g. "1,234").

Related errors


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