# How to make multiple meshs play different animations

**URL:** <https://forum.babylonjs.com/t/how-to-make-multiple-meshs-play-different-animations/33970>\
**Category:** Questions\
**Tags:** animation, mesh\
**Created:** [September 16, 2022, 3:10am UTC](https://forum.babylonjs.com/t/how-to-make-multiple-meshs-play-different-animations/33970 "2022-09-16T03:10:35Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![shahho](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/shahho/32/26934_2.png) [@shahho](https://forum.babylonjs.com/u/shahho)\
**Post date:** [September 16, 2022, 3:10am UTC](https://forum.babylonjs.com/t/how-to-make-multiple-meshs-play-different-animations/33970/1 "2022-09-16T03:10:35Z")

</div>

Hello friends:  
I have a .glb file with animations.  
It has 4 animations: ‘Walk, Sitdown, Idle, Standup’.  
I cloned multiple model files in the scene,  
hoping that each would play a different animation. Do you have any ideas?

Such as making character 1 walk、 Character 2 sitdown、 Character 3 idle at the same time.

this is the playground link:

> **[Babylon.js Playground](https://playground.babylonjs.com/#7VQJUY%2310)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

---

<div class="post-metadata">

**Author:** ![labris](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/labris/32/12576_2.png) [@labris](https://forum.babylonjs.com/u/labris)\
**Post date:** [September 16, 2022, 3:34am UTC](https://forum.babylonjs.com/t/how-to-make-multiple-meshs-play-different-animations/33970/2 "2022-09-16T03:34:12Z")

</div>

You need to clone animationGroups too and retarget them to corresponding nodes.  
Here is the example how simple it could be with the AssetContainer and `instantiateModelsToScene` function - [https://playground.babylonjs.com/#AJA5J6#184](https://playground.babylonjs.com/#AJA5J6#184)

---

<div class="post-metadata">

**Author:** ![shahho](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/shahho/32/26934_2.png) [@shahho](https://forum.babylonjs.com/u/shahho)\
**Post date:** [September 16, 2022, 5:51am UTC](https://forum.babylonjs.com/t/how-to-make-multiple-meshs-play-different-animations/33970/3 "2022-09-16T05:51:06Z")

</div>

thank you sir,  
and I have another problem:  
How to get from the Mesh what are the corresponding animations?  
I need to get the model first ，and then play the animation of the name in the model。

---

<div class="post-metadata">

**Author:** ![carolhmj](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/carolhmj/32/25918_2.png) [@carolhmj](https://forum.babylonjs.com/u/carolhmj)\
**Post date:** [September 16, 2022, 12:35pm UTC](https://forum.babylonjs.com/t/how-to-make-multiple-meshs-play-different-animations/33970/4 "2022-09-16T12:35:52Z")

</div>

There are many ways of doing this, but one of them can be simply to save on the model the associated information of the animationGroups: [animating-clones-from-glb | Babylon.js Playground (babylonjs.com)](https://playground.babylonjs.com/#AJA5J6#185)

---

<div class="post-metadata">

**Author:** ![shahho](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/shahho/32/26934_2.png) [@shahho](https://forum.babylonjs.com/u/shahho)\
**Post date:** [September 20, 2022, 9:29am UTC](https://forum.babylonjs.com/t/how-to-make-multiple-meshs-play-different-animations/33970/5 "2022-09-20T09:29:36Z")

</div>

thank you, \* I’ll give it a try。

---

<div class="post-metadata">

**Author:** ![shahho](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/shahho/32/26934_2.png) [@shahho](https://forum.babylonjs.com/u/shahho)\
**Post date:** [September 23, 2022, 7:59am UTC](https://forum.babylonjs.com/t/how-to-make-multiple-meshs-play-different-animations/33970/6 "2022-09-23T07:59:35Z")

</div>

hey brothers,  
I tried a new approach to clone multiple meshs to play different animations.  
like this:

```auto
private characterMap: Map<string, any> = new Map();
...
 async getCharacter(url: string) {
    return new Promise<any>((resolve: any, reject: any) => {
      if (this.characterMap.has(url)) {
        const origin = this.characterMap.get(url);
        const mesh = origin.clone()
        mesh.animations = this.cloneAnimations( origin.animations);
        resolve(mesh);
      } else {
        BABYLON.SceneLoader.ImportMesh('', '', url, undefined, (meshes: any[], particleSystems: any[], skeletons: any[], animationGroups: any[], transformNodes: any[], geometries: any[], lights: any[]) => {
          let origin = meshes[0] as BABYLON.Mesh;
          origin.animations = animationGroups;
          origin.setEnabled(false);
          this.modelMap.set(url, origin);
          const mesh = origin.clone();
          resolve(mesh);
        }, null, (err) => {
          console.log("has error: " + err)
          reject(err);
        });
      }
    });
  }
  private cloneAnimations(groups: BABYLON.AnimationGroup[]) {
    let temp = [];
    for (let i = 0; i < groups.length; i++) {
      const a = groups[i] as BABYLON.AnimationGroup;
      const b = a.clone(a.name+"_"+Tool.randomStr(6));
      temp.push(b)
    }
    return temp;
  }

```

and I used the code like this way:

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/3/2/32b0fc234a170be76f0ab1cd986ae13b5d02550b.png)

---

<div class="post-metadata">

**Author:** ![carolhmj](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/carolhmj/32/25918_2.png) [@carolhmj](https://forum.babylonjs.com/u/carolhmj)\
**Post date:** [September 23, 2022, 12:55pm UTC](https://forum.babylonjs.com/t/how-to-make-multiple-meshs-play-different-animations/33970/7 "2022-09-23T12:55:33Z")

</div>

It’s easier to us to follow your code if you provide a Playground repro 🙂
