# Best way to fully clone a Babylon.js scene for GLTF export (including hierarchy and textures)?

**URL:** https://forum.babylonjs.com/t/best-way-to-fully-clone-a-babylon-js-scene-for-gltf-export-including-hierarchy-and-textures/63016
**Category:** Questions
**Tags:** clone
**Created:** [April 1, 2026, 5:48pm UTC](https://forum.babylonjs.com/t/best-way-to-fully-clone-a-babylon-js-scene-for-gltf-export-including-hierarchy-and-textures/63016 "2026-04-01T17:48:07Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![andriisvityi](https://avatars.discourse-cdn.com/v4/letter/a/b9e5f3/32.png) [@andriisvityi](https://forum.babylonjs.com/u/andriisvityi)
#### Post date: [April 1, 2026, 5:48pm UTC](https://forum.babylonjs.com/t/best-way-to-fully-clone-a-babylon-js-scene-for-gltf-export-including-hierarchy-and-textures/63016/1 "2026-04-01T17:48:07Z")

</div>

Hi,

I’m trying to create a **full copy of an existing Babylon.js scene** in order to modify it and export it to GLTF without affecting the original scene.

### 🎯 Goal

- Clone the entire scene (nodes, meshes, hierarchy, lights, cameras)

- Keep **materials and textures shared or reused (no deep copy needed)**

- Preserve **complex hierarchy (including nested nodes and InstancedMesh)**

- Ensure textures are correctly exported into GLTF (`images` section is not empty)

* * *

### ❌ Problems I encountered

#### 1. Manual deep clone

I tried implementing my own recursive clone:

- cloning `TransformNode`, `Mesh`, `InstancedMesh`, etc.

- restoring parent hierarchy

But:

- very slow with large scenes (~48k nodes)

- breaks hierarchy in some cases (especially cabinets with nested nodes)

- `InstancedMesh` depends on cloning order

- hard to maintain correctness

* * *

#### 2. SceneSerializer + SceneLoader

I also tried:

```auto
const serialized = BABYLON.SceneSerializer.Serialize(scene);
const json = JSON.stringify(serialized);
const url = "data:application/json," + encodeURIComponent(json);

const newScene = await BABYLON.SceneLoader.LoadAsync("", url, engine);

```

This works much better for hierarchy, but I had issues where:

- textures were not always present in GLTF export (`images` array empty)

- likely because export was triggered before textures finished loading

* * *

### ❓ Questions

1. What is the **recommended way to fully clone a scene** in Babylon.js for export purposes?

2. Is there any built-in or recommended pattern to:

3. What is the correct way to ensure that:

4. Are there any known pitfalls when cloning scenes with:

* * *

### 💡 Current approach

Right now I:

- clone scene via `SceneSerializer + LoadAsync`

- await `scene.whenReadyAsync()`

- wait for all textures via `texture.onLoadObservable`

- then process scene and export

But I want to confirm if this is the correct and recommended approach.

* * *

Thanks in advance!

---

<div class="post-metadata">

### Author: ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)
#### Post date: [April 1, 2026, 7:32pm UTC](https://forum.babylonjs.com/t/best-way-to-fully-clone-a-babylon-js-scene-for-gltf-export-including-hierarchy-and-textures/63016/2 "2026-04-01T19:32:22Z")

</div>

I think some of the behaviors you are exposing are bugs mostly around the textures not being present in export. Could you share repro for them ?

cc @alexchuber

---

<div class="post-metadata">

### Author: ![andriisvityi](https://avatars.discourse-cdn.com/v4/letter/a/b9e5f3/32.png) [@andriisvityi](https://forum.babylonjs.com/u/andriisvityi)
#### Post date: [April 1, 2026, 8:10pm UTC](https://forum.babylonjs.com/t/best-way-to-fully-clone-a-babylon-js-scene-for-gltf-export-including-hierarchy-and-textures/63016/3 "2026-04-01T20:10:18Z")

</div>

> [@sebavan](#):
>
> I think some of the behaviors you are exposing are bugs mostly around the textures not being present in export. Could you share repro for them ?

public async createGltf(filename: string, scene?: BABYLON.Scene): Promise {

```
    await this.\_3dgo_prepareTool.prepareScene(scene);

    await this.\_3dgo_prepareTool.waitUntilReady();

    const exportScene = this.\_3dgo_prepareTool.get3DGOScene();

    return GLTF2Export.GLTFAsync(

        this.\_3dgo_prepareTool.get3DGOScene(),

        filename,

        {

            shouldExportNode: (node) => node.isEnabled()

    }

    );

}

```

[Scene clone class](https://www.filemail.com/d/xgjhpagbtkqyjhg)

---

<div class="post-metadata">

### Author: ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)
#### Post date: [April 1, 2026, 8:56pm UTC](https://forum.babylonjs.com/t/best-way-to-fully-clone-a-babylon-js-scene-for-gltf-export-including-hierarchy-and-textures/63016/4 "2026-04-01T20:56:54Z")

</div>

Can you repro in the playground as I am afraid it would depend on the actual scene unfortunately
