Best practice to pause the game in playcanvas

so i have a bunch of spawner scripts and moving scripts and they are using the update function to do what they do, now when the player changes browser tab, the game just stops but the code inside update or setInterval keeps on executing, is there a proper way to pause the game?

Hi @sir_akc! I think you can use the method below. = 0;

so this will stop all the action?
I am going to use this statement inside
and then turn it back on inside

wait how do you turn the game back on? =1;???

So yeah, timeScale handles most things.

For anything else that isn’t linked directly to the dt of the update function, you can also do something like:

if ( {'pausegame');

Then, in every script that needs to do something special:'pausegame', function () {
    // do whatever needs to be done to pause things correctly
}, this);
1 Like

well some code is running under SetInterval and I am using bool to check if game active or not and do accordingly, so far the most modular and easy way to handle

That’s correct.