BabylonJS/Babylon.js · error · Error

Scene is not available

Error message

Scene is not available

What it means

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.

Source

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

     * 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;
    }

    /**
     * The Babylon scene when loading the asset.
     */
    public get babylonScene(): Scene {
        if (!this._babylonScene) {
            throw new Error("Scene is not available");
        }

        return this._babylonScene;
    }

    /**
     * The root Babylon node when loading the asset.
     */
    public get rootBabylonMesh(): Nullable<TransformNode> {
        return this._rootBabylonMesh;
    }

    /**
     * The root url when loading the asset.
     */
    public get rootUrl(): Nullable<string> {
        return this._rootUrl;
    }

View on GitHub (pinned to 0592b347b8)

Solutions

  1. Access babylonScene only from lifecycle hooks that run after scene setup (e.g. onLoaded / during asset loading, not construction)
  2. Pass/keep a reference to your own Scene instead of reading it off the loader
  3. Guard with a null/state check before accessing the getter
  4. For JSON-only inspection, avoid scene-dependent code paths entirely

Example fix

// before
const loader = new GLTFLoader();
const scene = loader.babylonScene; // throws
// after
loader.onLoadedObservable.add(() => {
    const scene = loader.babylonScene;
});
Defensive patterns

Strategy: try-catch

Validate before calling

let scene: Scene | null = null;
try { scene = loader.babylonScene; } catch { /* not yet assigned */ }
if (!scene) throw new Error("Scene not ready — access babylonScene from onLoaded");

Type guard

function hasBabylonScene(loader: unknown): loader is { babylonScene: Scene } {
    try { return !!(loader as any)?.babylonScene; } catch { return false; }
}

Try / catch

try {
    const scene = loader.babylonScene;
    scene.getEngine().getRenderWidth();
} catch (e) {
    if (String(e.message).includes("Scene is not available")) {
        // retry inside onLoadedObservable
    } else throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


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