Play a death animation group and then stop (character is dead)

Hi all. Just wondering if I’m doing this right. The objective is to play a death animation and then stop. I was running into problems with the animation group instantly resetting after the death animation was done. So i’ve got a solution working where I loop through all of the animation groups, pause them, and then play the death animation with loop false. Works fine. But i feel like i’m missing a concept maybe?

Hello! :smiley: You got it right, it’s good to pause/stop the other animation groups as they can affect the same target and mess up the death animation. @PatrickRyan might have other useful pointers to share too.

1 Like

And on a side note - it is recommended to reset the animatiosn as well, if you want to be sure you start from the beginning. but I am sure @PatrickRyan will give a more detailed answer :slight_smile:

Or just… stop all animations :wink:

prova | Babylon.js Playground (

1 Like

@bigrig, there are a few things going on here. By default, when a glb with animation groups contained in it is loaded the animation groups will play by default. This means that all of your animation groups are playing once you load your model and your call for the walk animation to play in your code makes that the active group, but the others are all playing. Since your animations are full body animations, meaning there are no bones without keys on them, the active animation group is masking the fact that the others are playing since it is overriding the values for all the other clips. You can see this on a fresh load of the scene. Your idle is playing but if you look at death, it is actively playing as well:

You can see this if you let the scene play for a second once loaded and then press the death button. It will start wherever the death animation is currently playing in the timeline. This will cause a problem of knowing your exact state when you need to path between animations.

The quick fix for this is to stop animation groups as you are assigning them to your array:

for (let i = 0; i < allAGs.length; i++) {
          agMap[allAGs[i].name] = allAGs[i];

Stopping an animation group will reset the animation to start at frame 0. Pausing an animation group, as the name suggests, will keep the last animation frame played and pick back up there, so you can always use these to your advantage.

You definitely want to be managing your animation groups’ play state as your scene unfolds, and calling a stop on all scene animations like @RaananW suggested is good for a simple scene like this playground. But you will quickly run into issues with that once you add something else with animations to the scene since you don’t want to be controlling all scene animations on every mesh when one changes state.

So the best method is to keep track of which animation group is currently playing. If you have a character object, which I find is a great way to keep parameters for each character in the experience, add a key that holds the current animation group. When you change state, stop the current animation group, start the new one, and add the new group to the current animation group parameter. This will mean you always know what animation group is playing and can easily stop it when needed.

Here are those changes to your playground so you can easily keep state and make sure the rest are ready to play.

You might also want to take advantage of animation blending. This is an example of animation group blending. This also has animation retargeting in the example, but you can ignore that part if you are not sharing animations between assets. I hope this helps, but ping me with more questions.


Wow you answered so many long standing questions i had about how the animation groups interact. Makes sense now why sometimes the death anim would pickup in the middle. Thank you SO much.


ps. i’m using SSatGuru’s amazing character controller for my main player, but it doesn’t work well for other players since it’s got all the camera controls entangled. so am creating a secondary controller for 2ndary players. prob. would be a good idea for me to figure out how to adapt SSAT’s controller to control non-primary players instead.

SSATs’ controller also needs special handling for playing animations outside of the standard set (like this death animation). for some reason, the pauseAnim() option doesn’t work. need more digging there. Update: just saw he posted on github that it’s a bug. Awesome.