BabylonJS/Babylon.js · error

No scene available to export

Error message

No scene available to export

What it means

_GLTFExporter's constructor falls back to EngineStore.LastCreatedScene when no Scene is passed. If no scene exists at all (headless environment, engine not yet created, or scene already disposed), babylonScene is null and the exporter cannot gather meshes/materials to export, so it throws immediately.

Source

Thrown at packages/dev/serializers/src/glTF/2.0/glTFExporter.ts:422

                this._glTF.extensions ||= {};
                if (extension.onExporting) {
                    extension.onExporting();
                }
            }
        });
    }

    private _loadExtensions(): void {
        for (const name of GLTFExporter._ExtensionNames) {
            const extension = GLTFExporter._ExtensionFactories[name](this);
            this._extensions[name] = extension;
        }
    }

    public constructor(babylonScene: Nullable<Scene> = EngineStore.LastCreatedScene, options?: IExportOptions) {
        if (!babylonScene) {
            throw new Error("No scene available to export");
        }

        this._babylonScene = babylonScene;

        this._options = {
            shouldExportNode: () => true,
            shouldExportAnimation: () => true,
            metadataSelector: (metadata) => metadata?.gltf?.extras,
            animationSampleRate: 1 / 60,
            exportWithoutWaitingForScene: false,
            exportUnusedUVs: false,
            removeNoopRootNodes: true,
            includeCoordinateSystemConversionNodes: false,
            meshCompressionMethod: "None",
            ...options,
        };

        this._loadExtensions();

View on GitHub (pinned to 0592b347b8)

Solutions

  1. Pass the scene explicitly: new GLTFExporter(scene, options) instead of relying on LastCreatedScene
  2. Create a scene (new Engine(); new Scene(engine)) before constructing the exporter
  3. Verify the scene was not disposed before export; move exporter construction to after scene setup

Example fix

// before
const exporter = new GLTFExporter(); // throws in headless
// after
const exporter = new GLTFExporter(myScene, { shouldExportNode: () => true });
Defensive patterns

Strategy: try-catch

Validate before calling

import { EngineStore } from "core/Engines/engineStore";
if (!scene && !EngineStore.LastCreatedScene) {
  throw new Error("No scene available: create a Scene before constructing GLTFExporter");
}

Type guard

function sceneAvailable(s: Nullable<Scene>): s is Scene { return !!s; }

Try / catch

let exporter: GLTFExporter;
try {
  exporter = new GLTFExporter();
} catch (e) {
  if (String(e.message).includes("No scene available")) {
    exporter = new GLTFExporter(createHeadlessScene()); // ensure engine+scene exist
  } else throw e;
}

Prevention

When it happens

Trigger: Calling new GLTFExporter() (no arguments) in a Node/headless context with no created scene; calling it after scene.dispose() and engine cleanup; passing an explicitly null scene; importing the exporter before Babylon engine initialization.

Common situations: Server-side export scripts that never called new Engine / new Scene; tests running after a previous test disposed the last created scene; module-level singleton exporter instantiated at import time before the scene exists.

Related errors


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