Inconsistent behavior when setting loopAnimation to false

Hi !

When setting animationGroup.loopAnimation to false during the first cycle, the animation completes and stops as expected. However, when it is set to false during the second or a subsequent cycle, the animation stops immediately.

Playground: Babylon.js Playground

Hi!

This behavior is expected and is caused by changing animationGroup.loopAnimation at an arbitrary time using setTimeout.

loopAnimation is only evaluated when a cycle ends to decide whether the animation should start the next loop. When you change it during the first cycle, the current loop finishes normally and the animation stops as expected. However, on the second or subsequent cycles, the animation may already be at the end frame or between loops, so setting loopAnimation = false causes it to stop immediately.

The main issue here is that setTimeout is not synchronized with the animation timeline, so its timing is unreliable (FPS, speedRatio, animation length, etc.).

In Babylon.js, animation flow should be controlled using animation observables instead of timers.

Try this: Babylon.js Playground

2 Likes