{"record":{"id":"499e2e7a513859fb","repo":"BabylonJS/Babylon.js","slug":"could-not-clone-or-instantiate-node-on-asset-conta","errorCode":null,"errorMessage":"Could not clone or instantiate node on Asset Container ${node.name}","messagePattern":"Could not clone or instantiate node on Asset Container (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/dev/core/src/assetContainer.ts","lineNumber":651,"sourceCode":"                if (\r\n                    node.getClassName() === \"TransformNode\" ||\r\n                    node.getClassName() === \"Node\" ||\r\n                    (node as Mesh).skeleton ||\r\n                    !(node as any).getTotalVertices ||\r\n                    (node as Mesh).getTotalVertices() === 0\r\n                ) {\r\n                    // Transform nodes, skinned meshes, and meshes with no vertices can never be instanced!\r\n                    canInstance = false;\r\n                } else if (localOptions.doNotInstantiate) {\r\n                    if (typeof localOptions.doNotInstantiate === \"function\") {\r\n                        canInstance = !localOptions.doNotInstantiate(node);\r\n                    } else {\r\n                        canInstance = !localOptions.doNotInstantiate;\r\n                    }\r\n                }\r\n                const replicatedNode = canInstance ? (node as Mesh).createInstance(`instance of ${node.name}`) : node.clone(`Clone of ${node.name}`, null, true);\r\n                if (!replicatedNode) {\r\n                    throw new Error(`Could not clone or instantiate node on Asset Container ${node.name}`);\r\n                }\r\n                onNewCreated(node, replicatedNode);\r\n            }\r\n        }\r\n\r\n        for (const s of this.skeletons) {\r\n            if (localOptions.predicate && !localOptions.predicate(s)) {\r\n                continue;\r\n            }\r\n\r\n            const clone = s.clone(nameFunction ? nameFunction(s.name) : \"Clone of \" + s.name);\r\n\r\n            for (const m of this.meshes) {\r\n                if (m.skeleton === s && !m.isAnInstance) {\r\n                    const copy = storeMap[conversionMap[m.uniqueId]] as Mesh;\r\n                    if (!copy || copy.isAnInstance) {\r\n                        continue;\r\n                    }\r","sourceCodeStart":633,"sourceCodeEnd":669,"githubUrl":"https://github.com/BabylonJS/Babylon.js/blob/0592b347b8a4ee0236089ea86a749cacfdb266d8/packages/dev/core/src/assetContainer.ts#L633-L669","documentation":"instantiateModelsToScene() replicates nodes from the asset container into the scene by either creating an instance (for instanciable meshes) or cloning the node. clone()/createInstance() can return null (e.g. a mesh whose geometry/source failed); since a null node cannot be added to the scene, the manager throws an error naming the original node.","triggerScenarios":"A mesh in the container whose clone() returns null — commonly when the source mesh/geometry is missing or corrupted, or createInstance fails because the mesh lost its source; containers loaded from a malformed/glitched file where a TransformNode reports as instanciable but isn't a Mesh.","commonSituations":"Loading glTF/GLB assets with unsupported or broken mesh data; calling instantiateModelsToScene on a container whose meshes were disposed; options.doNotInstantiate semantics combined with nodes that cannot clone (custom subclasses returning null).","solutions":["Check the source asset: reload/re-export the container file (glTF/GLB) to fix nodes that fail to clone.","Avoid disposing container meshes/assets before instantiateModelsToScene runs.","Verify nodes are actual Meshes before instantiation is attempted, or pass doNotInstantiate: true so clone behavior is predictable.","Wrap instantiateModelsToScene in try/catch and log node.name to identify the offending asset; repair or remove that node.","Update to the latest Babylon.js version — clone/instance bugs for specific loaders have been fixed over time."],"exampleFix":"// before\nconst root = container.instantiateModelsToScene(); // throws on broken node\n// after\ntry {\n  const root = container.instantiateModelsToScene((m) => m.name, undefined, { doNotInstantiate: true });\n} catch (e) {\n  console.error('Instantiate failed:', e.message); // identify broken node\n}","handlingStrategy":"try-catch","validationCode":"const meshes = container.meshes.filter((n): n is Mesh => n instanceof Mesh);\nif (meshes.some((m) => !m.geometry)) {\n  console.warn('Container has meshes without geometry; instantiate may fail');\n}","typeGuard":"function isClonableMesh(node: Node): node is Mesh {\n  return node instanceof Mesh && node.geometry != null;\n}","tryCatchPattern":"try {\n  const root = container.instantiateModelsToScene();\n} catch (e) {\n  if (e instanceof Error && e.message.startsWith('Could not clone or instantiate')) {\n    console.error('Broken node in asset container:', e.message);\n    reloadOrRepairAssetContainer();\n    return;\n  }\n  throw e;\n}","preventionTips":["Validate loaded assets (meshes have geometry/source) before instantiating","Do not dispose container meshes before instantiateModelsToScene","Re-export/fix source glTF/GLB files that contain broken nodes","Use doNotInstantiate option when instance creation is flaky for your assets","Keep Babylon.js and loaders up to date to benefit from clone/instance fixes"],"tags":["asset-container","clone","instancing"],"backgroundTag":"node-clone-failed","analyzedSha":"0592b347b8a4ee0236089ea86a749cacfdb266d8","analyzedAt":"2026-08-30T15:11:20.442Z","schemaVersion":2},"datasetVersion":"2026-08-30T18:17:15.746Z"}