Using scene.stopAllAnimations does not remove all animatables from animationGroup and stops the onAnimationGroupEndObservable callback from being called

Hi there!

I am working on a project where I am loading a mesh with animations, and stopping all animations during initialization (because I want nothing animated at the beginning) using scene.stopAllAnimations(). But when this is done, the callbacks added to onAnimationGroupEndObservable are never called again.

You can see this here -

Steps -
Working scenario -

  1. Click the ‘Play’ button.
  2. Click the ‘Stop’ button. → The onAnimationGroupEndObservable callback is called and the first cube changes colour. All good!

Faulty scenario -

  1. Click the ‘Play’ button
  2. Click the ‘Stop All’. → The onAnimationGroupEndObservable callback is not called again.
  3. Click the ‘Play’ button.
  4. Click the ‘Stop’ button. → The onAnimationGroupEndObservable callback is not called.

I explored this a little, and it looks like the issue lies in the [src/Animations/animatable.ts] file in the Scene.prototype.stopAllAnimations method, where the for-loop to call this._activeAnimatables[i].stop(); should be reversed, since the animatable’s stop function splices the scene._activeAnimatables array.
At the moment, some of the _activeAnimatables are not stopped and their onAnimationEnd method is never raised using the stopAllAnimations method. This causes the onAnimationGroupEndObservable callback to never be called even after the animations have ended.

Thank you in advance :slight_smile:

Hello and welcome to the Babylon community! Thank you so much for the report and repro, I tested locally and can confirm that reversing the for loop fixes this :smiley: PR with the fix is here: Fix stopAllAnimatables stop loop order. by carolhmj · Pull Request #13683 · BabylonJS/Babylon.js (, it will be in the next release after merge :slight_smile:


Hi! Great to hear, thank you :smiley:

1 Like