{"record":{"id":"d8c31195c6a67aa0","repo":"BabylonJS/Babylon.js","slug":"scene-is-not-available","errorCode":null,"errorMessage":"Scene is not available","messagePattern":"Scene is not available","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/dev/loaders/src/glTF/2.0/glTFLoader.pure.ts","lineNumber":313,"sourceCode":"     * 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\n\r\n    /**\r\n     * The Babylon scene when loading the asset.\r\n     */\r\n    public get babylonScene(): Scene {\r\n        if (!this._babylonScene) {\r\n            throw new Error(\"Scene is not available\");\r\n        }\r\n\r\n        return this._babylonScene;\r\n    }\r\n\r\n    /**\r\n     * The root Babylon node when loading the asset.\r\n     */\r\n    public get rootBabylonMesh(): Nullable<TransformNode> {\r\n        return this._rootBabylonMesh;\r\n    }\r\n\r\n    /**\r\n     * The root url when loading the asset.\r\n     */\r\n    public get rootUrl(): Nullable<string> {\r\n        return this._rootUrl;\r\n    }\r","sourceCodeStart":295,"sourceCodeEnd":331,"githubUrl":"https://github.com/BabylonJS/Babylon.js/blob/0592b347b8a4ee0236089ea86a749cacfdb266d8/packages/dev/loaders/src/glTF/2.0/glTFLoader.pure.ts#L295-L331","documentation":"The `babylonScene` getter returns the Babylon Scene the loader is populating, but `_babylonScene` is only assigned once loading into a scene begins. Accessing the getter outside that window throws this error, preventing use of an undefined scene.","triggerScenarios":"Reading `loader.babylonScene` before the loader has been given a scene (e.g. before `_loadFile`/`_loadData` assigned it), in a plugin callback that fires before scene assignment, or in a headless/JSON-only context where no Babylon scene is created.","commonSituations":"glTF loader plugins accessing the scene too early in the load pipeline; unit tests constructing the loader without a scene; using the loader in pure-JSON inspection mode.","solutions":["Access babylonScene only from lifecycle hooks that run after scene setup (e.g. onLoaded / during asset loading, not construction)","Pass/keep a reference to your own Scene instead of reading it off the loader","Guard with a null/state check before accessing the getter","For JSON-only inspection, avoid scene-dependent code paths entirely"],"exampleFix":"// before\nconst loader = new GLTFLoader();\nconst scene = loader.babylonScene; // throws\n// after\nloader.onLoadedObservable.add(() => {\n    const scene = loader.babylonScene;\n});","handlingStrategy":"try-catch","validationCode":"let scene: Scene | null = null;\ntry { scene = loader.babylonScene; } catch { /* not yet assigned */ }\nif (!scene) throw new Error(\"Scene not ready — access babylonScene from onLoaded\");","typeGuard":"function hasBabylonScene(loader: unknown): loader is { babylonScene: Scene } {\n    try { return !!(loader as any)?.babylonScene; } catch { return false; }\n}","tryCatchPattern":"try {\n    const scene = loader.babylonScene;\n    scene.getEngine().getRenderWidth();\n} catch (e) {\n    if (String(e.message).includes(\"Scene is not available\")) {\n        // retry inside onLoadedObservable\n    } else throw e;\n}","preventionTips":["Access babylonScene only from post-scene-assignment lifecycle hooks (onLoaded, load promise resolution)","Keep your own Scene reference instead of round-tripping through the loader","In plugins, use the scene passed via loader lifecycle arguments, not the getter","In headless/JSON-inspection code, avoid scene-dependent paths"],"tags":["gltf","loader","lifecycle","scene"],"backgroundTag":"loader-state-not-ready","analyzedSha":"0592b347b8a4ee0236089ea86a749cacfdb266d8","analyzedAt":"2026-08-30T15:11:20.442Z","schemaVersion":2},"datasetVersion":"2026-08-30T18:17:15.746Z"}