How to import animation groups, then assign them to different meshes

Hi! I have two character meshes, both with identical skeletons. I’m wanting to import another .glb file containing animations for these characters, and then “assign” these animations to each character. This is what I’ve gotten so far:

//Import first character
BABYLON.SceneLoader.Append("", base64Uri, scene, (result) => {});

//Import second character
BABYLON.SceneLoader.Append("", base64Uri2, scene, (result) => {});

//Import animation(s)
BABYLON.SceneLoader.ImportAnimations(
    "folder/",
    "animations.glb",
    scene,
    (result) => {}
  );

All this does is play one of the animations for one character. How do I play the animation(s) for both characters, or assign an animation to character one, and another animation to character two? Basically, I just need to know how to manipulate my animation.glb once it’s been imported into the scene. Any advice is welcome!

I mentioned two ways how you can achieve copy animationgroups, in here:

2 Likes

Hi! Thanks for your reply. I tried using method number two in this playground: https://playground.babylonjs.com/#AHQEIB#1825 but for some reason it’s not working.

The result is, as you’ll see, that parts of the character mesh simply just get displaced. I’m still very new to animation in Babylonjs, so I apologize of I’m missing something obvious. Thanks in advance.

I assume your animations target bones not meshes.

So get the skeleton you want to animate on outer scope and use their bones as target like this:

newGroup.addTargetedAnimation(animation, globalSkeletons[0].bones.find(bone => bone.name === target.name))

Also I would exchange setTimeout with scene.onReadyObservable:

What I would check aswell is if using stop() on animationGroup can be enabled by play() or rather start()-function. From what I remember start() is opposite of stop() and play() is opposite of pause().

3 Likes

Hello @the ! Just checking in if you need any more help with this?