{"record":{"id":"1ccbb348413f94c3","repo":"BabylonJS/Babylon.js","slug":"gltf-json-is-not-available","errorCode":null,"errorMessage":"glTF JSON is not available","messagePattern":"glTF JSON is not available","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/dev/loaders/src/glTF/2.0/glTFLoader.pure.ts","lineNumber":288,"sourceCode":"        registerGLTFExtension(name, false, factory);\r\n    }\r\n\r\n    /**\r\n     * Unregisters a loader extension.\r\n     * @param name The name of the loader extension.\r\n     * @returns A boolean indicating whether the extension has been unregistered\r\n     * @deprecated Please use unregisterGLTFExtension instead.\r\n     */\r\n    public static UnregisterExtension(name: string): boolean {\r\n        return unregisterGLTFExtension(name);\r\n    }\r\n\r\n    /**\r\n     * The object that represents the glTF JSON.\r\n     */\r\n    public get gltf(): IGLTF {\r\n        if (!this._gltf) {\r\n            throw new Error(\"glTF JSON is not available\");\r\n        }\r\n\r\n        return this._gltf;\r\n    }\r\n\r\n    /**\r\n     * The BIN chunk of a binary glTF.\r\n     */\r\n    public get bin(): Nullable<IDataBuffer> {\r\n        return this._bin;\r\n    }\r\n\r\n    /**\r\n     * The parent file loader.\r\n     */\r\n    public get parent(): GLTFFileLoader {\r\n        return this._parent;\r\n    }\r","sourceCodeStart":270,"sourceCodeEnd":306,"githubUrl":"https://github.com/BabylonJS/Babylon.js/blob/0592b347b8a4ee0236089ea86a749cacfdb266d8/packages/dev/loaders/src/glTF/2.0/glTFLoader.pure.ts#L270-L306","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Read `.gltf` only after the asset is fully loaded (await the load promise or use onLoaded / ready state)","Check `loader.state` before accessing, or use the local glTF JSON you already have","In error paths, inspect loader's load error instead of assuming JSON is present","Cache the JSON from the completed-load callback instead of polling the getter"],"exampleFix":"// before\nconst loader = new GLTFLoader();\nloader.loadAsync(...);\nconsole.log(loader.gltf.asset); // throws if not parsed yet\n// after\nconst loader = new GLTFLoader();\nawait loader.loadAsync(...);\nconsole.log(loader.gltf.asset);","handlingStrategy":"type-guard","validationCode":"if (loader.state !== LOADER_LOADING_PHASE_DONE /* or await load first */) {\n    throw new Error(\"Cannot read loader.gltf before parsing completes\");\n}","typeGuard":"function hasGltfJson(loader: { gltf?: unknown } & Record<string, any>): boolean {\n    try { return loader.gltf != null; } catch { return false; }\n}","tryCatchPattern":"let gltfJson;\ntry {\n    gltfJson = loader.gltf;\n} catch (e) {\n    if (String(e.message).includes(\"glTF JSON is not available\")) {\n        gltfJson = null; // defer until load completes\n    } else throw e;\n}","preventionTips":["Always await loadAsync / the load promise before touching loader internals","Read the glTF JSON in onLoaded or the resolved promise value instead of polling","Check loader state/progress before accessing getters","Handle load failure paths — failed loads never populate _gltf"],"tags":["gltf","loader","lifecycle","async"],"backgroundTag":"loader-state-not-ready","analyzedSha":"0592b347b8a4ee0236089ea86a749cacfdb266d8","analyzedAt":"2026-08-30T15:11:20.442Z","schemaVersion":2},"datasetVersion":"2026-08-30T18:17:15.746Z"}