{"record":{"id":"79f7f584d96e8183","repo":"BabylonJS/Babylon.js","slug":"no-scene-available-to-append-to","errorCode":null,"errorMessage":"No scene available to append to","messagePattern":"No scene available to append to","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/dev/core/src/Loading/sceneLoader.ts","lineNumber":1077,"sourceCode":" * @param options an object that configures aspects of how the scene is loaded\r\n * @returns The loaded scene\r\n */\r\nexport async function loadSceneAsync(source: SceneSource, engine: AbstractEngine, options?: LoadOptions): Promise<Scene> {\r\n    return await LoadSceneAsync(source, engine, options);\r\n}\r\n\r\n// This is the core implementation of append scene\r\nasync function appendSceneCoreAsync(\r\n    rootUrl: string,\r\n    sceneFilename: SceneSource = \"\",\r\n    scene: Nullable<Scene> = EngineStore.LastCreatedScene,\r\n    onProgress?: Nullable<(event: ISceneLoaderProgressEvent) => void>,\r\n    pluginExtension?: Nullable<string>,\r\n    name = \"\",\r\n    pluginOptions: PluginOptions = {}\r\n): Promise<Scene> {\r\n    if (!scene) {\r\n        throw new Error(\"No scene available to append to\");\r\n    }\r\n\r\n    const fileInfo = GetFileInfo(rootUrl, sceneFilename);\r\n    if (!fileInfo) {\r\n        throw new Error(\"Cannot load file: a valid scene filename or root url was not provided.\");\r\n    }\r\n\r\n    const loadingToken = {};\r\n    scene.addPendingData(loadingToken);\r\n\r\n    if (SceneLoaderFlags.ShowLoadingScreen && !showingLoadingScreen) {\r\n        showingLoadingScreen = true;\r\n        scene.getEngine().displayLoadingUI();\r\n        scene.executeWhenReady(() => {\r\n            scene.getEngine().hideLoadingUI();\r\n            showingLoadingScreen = false;\r\n        });\r\n    }\r","sourceCodeStart":1059,"sourceCodeEnd":1095,"githubUrl":"https://github.com/BabylonJS/Babylon.js/blob/0592b347b8a4ee0236089ea86a749cacfdb266d8/packages/dev/core/src/Loading/sceneLoader.ts#L1059-L1095","documentation":"AppendScene-style APIs merge an external scene file into an existing Scene. This guard throws when the scene parameter is null/undefined, since there is no target scene to append nodes into.","triggerScenarios":"Calling SceneLoader.AppendAsync (appendScene core path) with scene explicitly null/undefined instead of an existing Scene instance.","commonSituations":"Calling AppendAsync expecting it to create a scene (it does not — use LoadAsync for that); scene disposed earlier and the variable nulled; a refactor renamed variables and scene became undefined at the call site.","solutions":["Create or reuse a Scene and pass it: AppendAsync(rootUrl, filename, scene).","Use SceneLoader.LoadAsync if the intent is to create a brand new scene from the file.","Guard that scene && !scene.isDisposed before invoking the append call."],"exampleFix":"// before\nawait SceneLoader.AppendAsync(\"assets/\", \"extra.glb\", null); // throws\n\n// after\nconst scene = new BABYLON.Scene(engine);\nawait SceneLoader.AppendAsync(\"assets/\", \"extra.glb\", scene);","handlingStrategy":"type-guard","validationCode":"if (!scene || scene.isDisposed) {\n  throw new Error(\"AppendAsync requires a live Scene to append into\");\n}","typeGuard":"function isUsableScene(s: unknown): s is BABYLON.Scene {\n  return s instanceof BABYLON.Scene && !s.isDisposed;\n}","tryCatchPattern":"try {\n  await BABYLON.SceneLoader.AppendAsync(root, file, scene);\n} catch (e) {\n  if ((e as Error).message === \"No scene available to append to\") {\n    console.error(\"Target scene missing — create a Scene first or use LoadAsync\");\n  }\n}","preventionTips":["Remember AppendAsync merges into an existing scene; use LoadAsync to create a new one.","Guard scene && !scene.isDisposed before append calls.","Create the scene immediately after the engine in app bootstrap so it is always available."],"tags":["loading","scene-loader","validation","null-check"],"backgroundTag":"missing-scene-reference","analyzedSha":"0592b347b8a4ee0236089ea86a749cacfdb266d8","analyzedAt":"2026-08-30T15:11:20.442Z","schemaVersion":2},"datasetVersion":"2026-08-30T18:17:15.746Z"}