Pause whole game with animatables

Hello,

I have read a few comments here that simply ‘stopping the render loop’ is enough to pause the game - if the code to start it exists outside of the babylon context - however i ran into an issue when i restarted the render loop again. My issue was that any animatables currently in a scene will instantly jump as if they had been running for the entire time it is paused.

I found a workaround for it using:

engine._performanceMonitor.reset(); //may not be needed
scene._animationTimeLast = performance.now

prior to calling runRenderLoop with my render function.

My concern here is that i am using an internal tracking variable which has no reason to be maintained across version changes. I’m wondering if there is a correct way to reset the timing for the animatable module, or if this should be tracked as a bug.

1 Like

The scene has a public reset method:

scene.resetLastAnimationTimeFrame() should do the trick.

And you are right, the first line is not needed.

2 Likes

Ah, i see it now. didn’t spot it as i was looking at the animatables override of _animate whilst trying to work out why it was skipping.

would be nice if it was done automatically when calling runRenderLoop with an empty set of render functions.

oh right, runRenderLoop and Scene are not linked… i guess that explains why it needs to be done manually…

1 Like

This is a scenario where the developer needs to take action in order to get that to work correctly. Babylon doesn’t know in what state your scene is at or if you want to keep the behavior as is or not. In some cases you would want this behavior to stay the same (for example when you stop the render loop when moving to a different tab and coming back, you would expect the animation to “run in the background”).