BabylonJS/Babylon.js · error

BabylonScenePathToObjectConverter: path "${path}" is missing

Error message

BabylonScenePathToObjectConverter: path "${path}" is missing an instance id.

What it means

Beyond the special '<collection>.length' form, resolving an instance requires at least a second segment: the instance's uniqueId. If the path stops after the collection name (only one segment remains), there is no id to look up, so the library throws. This distinguishes collection-level references from the instance/property references the converter is designed to resolve.

Source

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

        const parts = tail.split("/").filter((p) => p.length > 0);
        if (parts.length === 0) {
            throw new Error(`BabylonScenePathToObjectConverter: path "${path}" is missing a collection name.`);
        }

        const collectionName = parts[0];
        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.

View on GitHub (pinned to 0592b347b8)

Solutions

  1. Append the instance uniqueId (and optionally the property) to the path, e.g. ".../transformNodes/42" or ".../transformNodes/42/position".
  2. If you need the collection size, use the '<collection>.length' form instead, e.g. ".../transformNodes/length".
  3. Guard the path builder to refuse emitting a pointer with fewer than two segments after the prefix.

Example fix

// before
converter.convert(`${prefix}transformNodes`); // missing id
// after
converter.convert(`${prefix}transformNodes/42/position`);
Defensive patterns

Strategy: validation

Validate before calling

const parts = path.slice(BABYLON_SCENE_OBJECT_MODEL_PREFIX.length).split("/").filter(Boolean);
if (parts.length === 1) {
  throw new Error(`Pointer needs an instance id (or use '<collection>.length'): ${path}`);
}
converter.convert(path);

Type guard

function hasInstanceId(path: string): boolean {
  const parts = path.slice(BABYLON_SCENE_OBJECT_MODEL_PREFIX.length).split("/").filter(Boolean);
  return parts.length === 2 && parts[1] === "length" || parts.length >= 2;
}

Try / catch

try {
  const info = converter.convert(path);
} catch (e) {
  // collection-only pointer; use '<collection>.length' or append the id
}

Prevention

When it happens

Trigger: convert() called with a path like "/extensions/BABYLON_scene_objects/transformNodes" (collection only, no id, and not the "/length" form); a builder that omitted the id segment.

Common situations: Wanting a handle to a whole collection and assuming the converter supports it (it only supports '<collection>.length'); path truncation when the id variable was empty; confusing the generic glTF path converter's semantics with this one.

Related errors


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