{"record":{"id":"fe4926161eca15f1","repo":"BabylonJS/Babylon.js","slug":"no-scene-available-to-export","errorCode":null,"errorMessage":"No scene available to export","messagePattern":"No scene available to export","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/dev/serializers/src/glTF/2.0/glTFExporter.ts","lineNumber":422,"sourceCode":"\r\n                this._glTF.extensions ||= {};\r\n                if (extension.onExporting) {\r\n                    extension.onExporting();\r\n                }\r\n            }\r\n        });\r\n    }\r\n\r\n    private _loadExtensions(): void {\r\n        for (const name of GLTFExporter._ExtensionNames) {\r\n            const extension = GLTFExporter._ExtensionFactories[name](this);\r\n            this._extensions[name] = extension;\r\n        }\r\n    }\r\n\r\n    public constructor(babylonScene: Nullable<Scene> = EngineStore.LastCreatedScene, options?: IExportOptions) {\r\n        if (!babylonScene) {\r\n            throw new Error(\"No scene available to export\");\r\n        }\r\n\r\n        this._babylonScene = babylonScene;\r\n\r\n        this._options = {\r\n            shouldExportNode: () => true,\r\n            shouldExportAnimation: () => true,\r\n            metadataSelector: (metadata) => metadata?.gltf?.extras,\r\n            animationSampleRate: 1 / 60,\r\n            exportWithoutWaitingForScene: false,\r\n            exportUnusedUVs: false,\r\n            removeNoopRootNodes: true,\r\n            includeCoordinateSystemConversionNodes: false,\r\n            meshCompressionMethod: \"None\",\r\n            ...options,\r\n        };\r\n\r\n        this._loadExtensions();\r","sourceCodeStart":404,"sourceCodeEnd":440,"githubUrl":"https://github.com/BabylonJS/Babylon.js/blob/0592b347b8a4ee0236089ea86a749cacfdb266d8/packages/dev/serializers/src/glTF/2.0/glTFExporter.ts#L404-L440","documentation":"_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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Pass the scene explicitly: new GLTFExporter(scene, options) instead of relying on LastCreatedScene","Create a scene (new Engine(); new Scene(engine)) before constructing the exporter","Verify the scene was not disposed before export; move exporter construction to after scene setup"],"exampleFix":"// before\nconst exporter = new GLTFExporter(); // throws in headless\n// after\nconst exporter = new GLTFExporter(myScene, { shouldExportNode: () => true });","handlingStrategy":"try-catch","validationCode":"import { EngineStore } from \"core/Engines/engineStore\";\nif (!scene && !EngineStore.LastCreatedScene) {\n  throw new Error(\"No scene available: create a Scene before constructing GLTFExporter\");\n}","typeGuard":"function sceneAvailable(s: Nullable<Scene>): s is Scene { return !!s; }","tryCatchPattern":"let exporter: GLTFExporter;\ntry {\n  exporter = new GLTFExporter();\n} catch (e) {\n  if (String(e.message).includes(\"No scene available\")) {\n    exporter = new GLTFExporter(createHeadlessScene()); // ensure engine+scene exist\n  } else throw e;\n}","preventionTips":["Always pass the Scene explicitly instead of relying on LastCreatedScene","Construct the exporter after Engine and Scene initialization, not at module import time","Check scene.isDisposed / disposed state before exporting in long-running processes"],"tags":["gltf","scene","lifecycle","export","initialization"],"backgroundTag":"no-active-scene","analyzedSha":"0592b347b8a4ee0236089ea86a749cacfdb266d8","analyzedAt":"2026-08-30T15:11:20.442Z","schemaVersion":2},"datasetVersion":"2026-08-30T18:17:15.746Z"}