{"record":{"id":"711dcd822982e4a5","repo":"BabylonJS/Babylon.js","slug":"no-scene-available-to-import-mesh-to","errorCode":null,"errorMessage":"No scene available to import mesh to","messagePattern":"No scene available to import mesh to","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/dev/core/src/Loading/sceneLoader.ts","lineNumber":980,"sourceCode":" * @returns The loaded list of imported meshes, particle systems, skeletons, and animation groups\r\n */\r\nexport async function ImportMeshAsync(source: SceneSource, scene: Scene, options?: ImportMeshOptions): Promise<ISceneLoaderAsyncResult> {\r\n    const { meshNames, rootUrl = \"\", onProgress, pluginExtension, name, pluginOptions } = options ?? {};\r\n    return await importMeshCoreAsync(meshNames, rootUrl, source, scene, onProgress, pluginExtension, name, pluginOptions);\r\n}\r\n\r\nasync function importMeshCoreAsync(\r\n    meshNames: string | readonly string[] | null | undefined,\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<ISceneLoaderAsyncResult> {\r\n    if (!scene) {\r\n        throw new Error(\"No scene available to import mesh 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    const progressHandler = wrapProgress(onProgress);\r\n\r\n    try {\r\n        const { plugin, data, responseURL } = await loadDataAsync(fileInfo, scene, progressHandler, pluginExtension ?? null, name, pluginOptions);\r\n\r\n        if (plugin.rewriteRootURL) {\r\n            fileInfo.rootUrl = plugin.rewriteRootURL(fileInfo.rootUrl, responseURL);\r\n        }\r","sourceCodeStart":962,"sourceCodeEnd":998,"githubUrl":"https://github.com/BabylonJS/Babylon.js/blob/0592b347b8a4ee0236089ea86a749cacfdb266d8/packages/dev/core/src/Loading/sceneLoader.ts#L962-L998","documentation":"ImportMesh-style core APIs need a Scene instance to add imported meshes/nodes to. This guard throws when the scene parameter is null/undefined at the start of the import routine, before any file info is resolved.","triggerScenarios":"Calling SceneLoader.ImportMeshAsync / appendScene core path with scene explicitly passed as null or an undefined variable.","commonSituations":"Awaiting an engine/scene creation promise and calling import before it resolves; a variable shadowing or clearing the scene reference after disposal; passing arguments in the wrong order so scene is undefined.","solutions":["Create the scene first (new Scene(engine)) and pass it to the import call.","If you want the engine-only convenience API, use SceneLoader.LoadAsync / AppendAsync which create the scene internally.","Check that the scene has not been disposed and the variable holds a Scene instance before importing."],"exampleFix":"// before\nawait SceneLoader.ImportMeshAsync(\"\", root, \"model.glb\", null); // throws\n\n// after\nconst scene = new BABYLON.Scene(engine);\nawait SceneLoader.ImportMeshAsync(\"\", root, \"model.glb\", scene);","handlingStrategy":"type-guard","validationCode":"if (!scene || scene.isDisposed) {\n  throw new Error(\"ImportMeshAsync requires a live Scene instance\");\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.ImportMeshAsync(\"\", root, file, scene);\n} catch (e) {\n  if ((e as Error).message === \"No scene available to import mesh to\") {\n    console.error(\"Scene was null — initialize the scene before importing\");\n  }\n}","preventionTips":["Await engine/scene initialization promises before starting imports.","Check scene && !scene.isDisposed before any loader call.","Use LoadAsync when you want the library to create the scene for you."],"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"}