# How to clone a gltf?

**URL:** <https://discourse.threejs.org/t/how-to-clone-a-gltf/78858>\
**Category:** Questions\
**Tags:** clone, gltf\
**Created:** [March 2, 2025, 1:02pm UTC](https://discourse.threejs.org/t/how-to-clone-a-gltf/78858 "2025-03-02T13:02:48Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![twisted](https://avatars.discourse-cdn.com/v4/letter/t/f04885/32.png) [@twisted](https://discourse.threejs.org/u/twisted)\
**Post date:** [March 2, 2025, 1:02pm UTC](https://discourse.threejs.org/t/how-to-clone-a-gltf/78858/1 "2025-03-02T13:02:48Z")

</div>

I want to use several instances of a model, defined in a glb file, in a game.

Rather than get the glb file over the network multiple times, I want to just get it once and then clone it. But I can’t see how to do that cloning.

Here is what I’m trying so far:

```javascript
    const CHARACTER_PATH = "/models/character.glb";                                                                                                                                        
                                                                                                                                                                                                
    let myGltf, myClone;                                                                                                                                                                        
                                                                                                                                                                                                
    //Promisified version of GLTFLoader.load()                                                                                                                                                  
    function loadGLTF(url) {                                                                                                                                                                    
      return new Promise((resolve, reject) => {                                                                                                                                                 
        new GLTFLoader().load(                                                                                                                                                                  
          url,                                                                                                                                                                                  
          (gltf) => resolve(gltf),                                                                                                                                                              
          undefined, //loading progress unused                                                                                                                                 
          (error) => reject(error)                                                                                                                                                              
        );                                                                                                                                                                                      
      });                                                                                                                                                                                       
    }                                                                                                                                                                                           
                                                                                                                                                                                                
    loadGLTF(CHARACTER_PATH)                                                                                                                                                                    
      .then((gltf) => {                                                                                                                                                                         
        myGltf = gltf; //ok                                                                                                                                                                          
// myClone = structuredClone(myGltf); //DomException                                                                                                                                      
      })                                                                                                                                                                                        
      .catch((error) => {                                                                                                                                                                       
        console.log(error);                                                                                                                                                                     
      }); 

```

I can’t just use a clone of gltf.scene because the animations are in gltf.animations.

Any help appreciated.

---

<div class="post-metadata">

**Author:** ![donmccurdy](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/donmccurdy/32/33209_2.png) [@donmccurdy](https://discourse.threejs.org/u/donmccurdy)\
**Post date:** [March 2, 2025, 1:09pm UTC](https://discourse.threejs.org/t/how-to-clone-a-gltf/78858/2 "2025-03-02T13:09:58Z")

</div>

The objects returned by the GLTFLoader are standard three.js class instances like [THREE.Object3D](https://threejs.org/docs/?q=object3d#api/en/core/Object3D) and [THREE.Mesh](https://threejs.org/docs/?q=mesh#api/en/objects/Mesh), you can use [`Object3D#clone()`](https://threejs.org/docs/?q=mesh#api/en/core/Object3D.clone) or other methods on them. Animations shouldn’t be an issue as long as your animations are on named objects, just used the cloned object as the ‘root’ in your AnimationMixer.

The one exception is if you’re using skinning/armature animation. In that case to keep bones associated with the SkinnedMesh skeleton correctly you’d need to clone the root object(s) with [SkeletonUtils.clone](https://threejs.org/docs/?q=skeleton#examples/en/utils/SkeletonUtils.clone) instead.

---

<div class="post-metadata">

**Author:** ![twisted](https://avatars.discourse-cdn.com/v4/letter/t/f04885/32.png) [@twisted](https://discourse.threejs.org/u/twisted)\
**Post date:** [March 2, 2025, 1:43pm UTC](https://discourse.threejs.org/t/how-to-clone-a-gltf/78858/3 "2025-03-02T13:43:15Z")

</div>

Thanks Don,

> use Object3D#clone() or other methods on them

I can’t call .clone() on the gltf in the loader:

```javascript
    const CHARACTER_PATH = "/models/character.glb";                                                                                                                                        
                                                                                                                                                                                                
    let myGltf, myClone;                                                                                                                                                                        
                                                                                                                                                                                                
    //Promisified version of GLTFLoader.load()                                                                                                                                                  
    function loadGLTF(url) {                                                                                                                                                                    
      return new Promise((resolve, reject) => {                                                                                                                                                 
        new GLTFLoader().load(                                                                                                                                                                  
          url,                                                                                                                                                                                  
          (gltf) => resolve(gltf),                                                                                                                                                              
          undefined, //loading progress unused                                                                                                                                 
          (error) => reject(error)                                                                                                                                                              
        );                                                                                                                                                                                      
      });                                                                                                                                                                                       
    }                                                                                                                                                                                           
                                                                                                                                                                                                
    loadGLTF(CHARACTER_PATH)                                                                                                                                                                    
      .then((gltf) => {                                                                                                                                                                         
        myGltf = gltf; //ok                                                                                                                                                                
        myClone = gltf.clone(); //TypeError: gltf.clone is not a function                                                                                                                                                            
      })                                                                                                                                                                                        
      .catch((error) => {                                                                                                                                                                       
        console.log(error);                                                                                                                                                                     
      });      

```

Could you clarify what I call .clone() on?

---

<div class="post-metadata">

**Author:** ![Lukasz\_Mestales](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/lukasz_mestales/32/65638_2.png) [@Lukasz\_Mestales](https://discourse.threejs.org/u/Lukasz_Mestales)\
**Post date:** [March 2, 2025, 2:34pm UTC](https://discourse.threejs.org/t/how-to-clone-a-gltf/78858/4 "2025-03-02T14:34:30Z")

</div>

I see `character` in your path name, so it will most likely be a skeleton model… Try this approach:

```javascript
import * as SkeletonUtils from 'three/addons/utils/SkeletonUtils.js';

//....

const CHARACTER_PATH = "https://threejs.org/examples/models/gltf/RobotExpressive/RobotExpressive.glb";
  let myGltf, myClone;

  function loadGLTF(url) {
  return new Promise((resolve, reject) => {
    new GLTFLoader().load(
      url,
      (gltf) => resolve(gltf),
      undefined,                                            
      (error) => reject(error)
    );
  });
}

loadGLTF(CHARACTER_PATH)
  .then((gltf) => {
    scene.add(gltf.scene);

    const clone = SkeletonUtils.clone(gltf.scene);
    gltf.scene.position.x = -2;
    gltf.scene.position.y = -2;
    clone.position.x = 2;
    clone.position.y = -2;
    scene.add(clone);
  })
  .catch((error) => {
    console.log(error);
  });

```

https://codepen.io/Lucas_Mas/embed/preview/MYWJMrY?default-tabs=html%2Cresult&height=300&host=https%3A%2F%2Fcodepen.io&slug-hash=MYWJMrY

---

<div class="post-metadata">

**Author:** ![donmccurdy](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/donmccurdy/32/33209_2.png) [@donmccurdy](https://discourse.threejs.org/u/donmccurdy)\
**Post date:** [March 2, 2025, 3:18pm UTC](https://discourse.threejs.org/t/how-to-clone-a-gltf/78858/5 "2025-03-02T15:18:06Z")

</div>

The top-level result is a plain object containing various data, not all Object3D scene graph objects. To clone the default scene you’d select and clone that only:

```javascript
const scene = gltf.scene;
const scene2 = scene.clone();

```

There’s no need to clone AnimationClip objects, they can be reused as-is.

More details on the response in the [GLTFLoader docs](https://threejs.org/docs/?q=GLTFLoad#examples/en/loaders/GLTFLoader).

---

<div class="post-metadata">

**Author:** ![twisted](https://avatars.discourse-cdn.com/v4/letter/t/f04885/32.png) [@twisted](https://discourse.threejs.org/u/twisted)\
**Post date:** [March 2, 2025, 3:40pm UTC](https://discourse.threejs.org/t/how-to-clone-a-gltf/78858/6 "2025-03-02T15:40:57Z")

</div>

> [@donmccurdy](#):
>
> There’s no need to clone AnimationClip objects, they can be reused as-is.

Maybe that’s the bit I was missing.

In the game, suppose I have 10 characters running around. Each character has its own AnimationMixer.

But, all I need is a single copy of the animations array?

For a particular character, I can take an AnimationClip from animations and use that character’s mixer.clipAction() to generate an AnimationAction?

I now have a ‘global’ set of AnimationClip objects but each character has it’s own set of AnimationAction objects.

And it works!

Thanks to Don & Lukasz.

---

<div class="post-metadata">

**Author:** ![donmccurdy](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/donmccurdy/32/33209_2.png) [@donmccurdy](https://discourse.threejs.org/u/donmccurdy)\
**Post date:** [March 2, 2025, 7:31pm UTC](https://discourse.threejs.org/t/how-to-clone-a-gltf/78858/7 "2025-03-02T19:31:20Z")

</div>

> [@twisted](#):
>
> For a particular character, I can take an AnimationClip from animations and use that character’s mixer.clipAction() to generate an AnimationAction?

That’s fine yes – The clips are reusable, the actions are specific to that character/object.

The exception is that if the objects in your glTF file are unnamed (which is not common) then three.js will create AnimationClip objects that target those objects [by UUID](https://threejs.org/docs/?q=object3d#api/en/core/Object3D.id). Then the cloned objects would have different UUIDs, so the animation wouldn’t play on them. But as long as your objects have names, the cloned objects will have the same names, the animation finds those names within the root passed to the AnimationMixer, and everything works fine.

---

<div class="post-metadata">

**Author:** ![byDezign](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/bydezign/32/24605_2.png) [@byDezign](https://discourse.threejs.org/u/byDezign)\
**Post date:** [May 13, 2025, 1:38am UTC](https://discourse.threejs.org/t/how-to-clone-a-gltf/78858/8 "2025-05-13T01:38:05Z")

</div>

Question, Doesn’t the Object3D clone method though only clone the Object data? Wouldnt the materials and textures be references to each other?

---

<div class="post-metadata">

**Author:** ![donmccurdy](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/donmccurdy/32/33209_2.png) [@donmccurdy](https://discourse.threejs.org/u/donmccurdy)\
**Post date:** [May 13, 2025, 2:14am UTC](https://discourse.threejs.org/t/how-to-clone-a-gltf/78858/9 "2025-05-13T02:14:13Z")

</div>

I think the idea is that `.clone()` creates a copy of the subset of the scene graph under the source object. Reusable resources like materials, textures, and geometry are not copied, but are shared between the source and cloned objects unless you explicitly reassign them.
