BabylonJS/Babylon.js · error

glTF JSON is not available

Error message

glTF JSON is not available

What it means

The `gltf` getter on the loader exposes the parsed glTF JSON, but only after the JSON has been fetched and parsed into `_gltf`. Accessing it earlier throws this error. It is a guard against using loader state during the loading lifecycle before the JSON exists.

Source

Thrown at packages/dev/loaders/src/glTF/2.0/glTFLoader.pure.ts:288

        registerGLTFExtension(name, false, factory);
    }

    /**
     * Unregisters a loader extension.
     * @param name The name of the loader extension.
     * @returns A boolean indicating whether the extension has been unregistered
     * @deprecated Please use unregisterGLTFExtension instead.
     */
    public static UnregisterExtension(name: string): boolean {
        return unregisterGLTFExtension(name);
    }

    /**
     * The object that represents the glTF JSON.
     */
    public get gltf(): IGLTF {
        if (!this._gltf) {
            throw new Error("glTF JSON is not available");
        }

        return this._gltf;
    }

    /**
     * The BIN chunk of a binary glTF.
     */
    public get bin(): Nullable<IDataBuffer> {
        return this._bin;
    }

    /**
     * The parent file loader.
     */
    public get parent(): GLTFFileLoader {
        return this._parent;
    }

View on GitHub (pinned to 0592b347b8)

Solutions

  1. Read `.gltf` only after the asset is fully loaded (await the load promise or use onLoaded / ready state)
  2. Check `loader.state` before accessing, or use the local glTF JSON you already have
  3. In error paths, inspect loader's load error instead of assuming JSON is present
  4. Cache the JSON from the completed-load callback instead of polling the getter

Example fix

// before
const loader = new GLTFLoader();
loader.loadAsync(...);
console.log(loader.gltf.asset); // throws if not parsed yet
// after
const loader = new GLTFLoader();
await loader.loadAsync(...);
console.log(loader.gltf.asset);
Defensive patterns

Strategy: type-guard

Validate before calling

if (loader.state !== LOADER_LOADING_PHASE_DONE /* or await load first */) {
    throw new Error("Cannot read loader.gltf before parsing completes");
}

Type guard

function hasGltfJson(loader: { gltf?: unknown } & Record<string, any>): boolean {
    try { return loader.gltf != null; } catch { return false; }
}

Try / catch

let gltfJson;
try {
    gltfJson = loader.gltf;
} catch (e) {
    if (String(e.message).includes("glTF JSON is not available")) {
        gltfJson = null; // defer until load completes
    } else throw e;
}

Prevention

When it happens

Trigger: Reading `loader.gltf` before the load promise resolves, before `onLoaded`/state reaches the appropriate phase, or when loading failed so `_gltf` was never assigned; accessing it synchronously right after constructing/starting the load.

Common situations: Subscribing to data outside the lifecycle callbacks and reading the JSON immediately; calling `whenCompleteAsync`-style flows incorrectly; reacting to early loader events (e.g. onPluginLoaded) that fire before parsing.

Related errors


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