Same AnimationGroup names - not allowed to control

I loaded two identical models onto the scene with AnimationGroup, and all AnimationGroup names duplicated. Can’t call AnimationGroup by name. Please help and sorry for the eng

Welcome aboard!

scene.getAnimationGroupByName returns the first animation group with the given name, so you won’t be able to retrieve both groups. After you load the first file, you should rename the animation groups so that there are no duplicate names.

2 Likes

What I see you’re working with Mixamo models using the same skeleton and surely you´re reusing the animations.

In this case, you’ve a more viable and efficient option:

  • Import the animations only once.
  • Then import the characters base without animations.
  • Clone the previously imported animations to them.

Here you have an example:

var player, animationsGLB;
function importAnimatios(scene, animation) {
    BABYLON.SceneLoader.ImportMeshAsync( null, "./resources/models/" + animation, null, scene).then((result1) =>{
        animationsGLB = result1;
    });
}


function importModel(scene, model) {
    BABYLON.SceneLoader.ImportMeshAsync( null, "./resources/models/" + model, null, scene).then((result2) =>{
        player = result2.meshes[0];
        const modelTransformNodes = player.getChildTransformNodes();
        var modelAnimationGroup;
        animationsGLB.animationGroups.forEach(animation => {
            modelAnimationGroup = animation.clone(animation.name + "_clone", (oldTarget) => {
                return modelTransformNodes.find((node) => node.name === oldTarget.name);
            });
            animation.dispose();
        });
        
        console.log("Animations: " + scene.animationGroups);
        scene.animationGroups[0].play(true, 1.0);
        //scene.getAnimationGroupByName("dance01_clone").play(true, 1.0);

    });
}

This way you will only import the animation file once and it will be easier for you to identify them.
In the clone part you can create a function to rename the animation.

Hope it helps

4 Likes