How to make multiple meshs play different animations

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:

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 -

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。

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 (

1 Like

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

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

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);
      } 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;
          this.modelMap.set(url, origin);
          const mesh = origin.clone();
        }, null, (err) => {
          console.log("has error: " + 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("_"+Tool.randomStr(6));
    return temp;

and I used the code like this way:

1 Like

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