BabylonJS/Babylon.js · error
Could not clone or instantiate node on Asset Container ${nod
Error message
Could not clone or instantiate node on Asset Container ${node.name} What it means
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.
Source
Thrown at packages/dev/core/src/assetContainer.ts:651
if (
node.getClassName() === "TransformNode" ||
node.getClassName() === "Node" ||
(node as Mesh).skeleton ||
!(node as any).getTotalVertices ||
(node as Mesh).getTotalVertices() === 0
) {
// Transform nodes, skinned meshes, and meshes with no vertices can never be instanced!
canInstance = false;
} else if (localOptions.doNotInstantiate) {
if (typeof localOptions.doNotInstantiate === "function") {
canInstance = !localOptions.doNotInstantiate(node);
} else {
canInstance = !localOptions.doNotInstantiate;
}
}
const replicatedNode = canInstance ? (node as Mesh).createInstance(`instance of ${node.name}`) : node.clone(`Clone of ${node.name}`, null, true);
if (!replicatedNode) {
throw new Error(`Could not clone or instantiate node on Asset Container ${node.name}`);
}
onNewCreated(node, replicatedNode);
}
}
for (const s of this.skeletons) {
if (localOptions.predicate && !localOptions.predicate(s)) {
continue;
}
const clone = s.clone(nameFunction ? nameFunction(s.name) : "Clone of " + s.name);
for (const m of this.meshes) {
if (m.skeleton === s && !m.isAnInstance) {
const copy = storeMap[conversionMap[m.uniqueId]] as Mesh;
if (!copy || copy.isAnInstance) {
continue;
}
View on GitHub (pinned to 0592b347b8)
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.
Example fix
// before
const root = container.instantiateModelsToScene(); // throws on broken node
// after
try {
const root = container.instantiateModelsToScene((m) => m.name, undefined, { doNotInstantiate: true });
} catch (e) {
console.error('Instantiate failed:', e.message); // identify broken node
} Defensive patterns
Strategy: try-catch
Validate before calling
const meshes = container.meshes.filter((n): n is Mesh => n instanceof Mesh);
if (meshes.some((m) => !m.geometry)) {
console.warn('Container has meshes without geometry; instantiate may fail');
} Type guard
function isClonableMesh(node: Node): node is Mesh {
return node instanceof Mesh && node.geometry != null;
} Try / catch
try {
const root = container.instantiateModelsToScene();
} catch (e) {
if (e instanceof Error && e.message.startsWith('Could not clone or instantiate')) {
console.error('Broken node in asset container:', e.message);
reloadOrRepairAssetContainer();
return;
}
throw e;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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).
Related errors
- Instanced arrays are required for MSDF text rendering.
- No scene available to load asset container to
- ${extensionContext}/attributes: Instance buffer accessors do
AI-assisted analysis of BabylonJS/Babylon.js@0592b347b8 (2026-08-30).
Data as JSON: /api/errors/499e2e7a513859fb.
Report an issue: GitHub.