How can I pause a game?

i tried using the set_time_step but it didnt really pause the game

1 Like

@britzl has a nice example here

Also, see the documentation for set_time_step

4 Likes

Keep in mind that the update() function of scripts will still be called, but dt is 0

1 Like

When I ran the code it paused some components but not all. Does the factory component have anything to do with it ?

What components were still running? Remember that you’re pausing anything coming from that specific collection (and sub collections if I’m not mistaken). Other collections will continue running.

Been battling to try and get this working for a bit as I needed to tackle this same problem. Some notes as I had quite a bit of trouble along the way - maybe it’ll help someone else out.

  1. As mentioned by @britzl, the update() function is still called - if something is still moving, check how its movement is handled. If you don’t need dt to calculate movement (my background images were just moving by a property value), you can still just stick a dt == 0 check at the start of the update function and return.
  2. (If the world appears to be duplicated) Try changing the bootstrap main collection (in game.project) to the pause collection so that the collection proxy loaded by the GUI script is the only world to load (and if you get errors after changing this main collection, make sure your collection isn’t called “default”!).
    I had to change a bunch of references to other game objects / components after changing this main collection as well - not sure what the reason for this was but fortunately I didn’t have that many to change. I also had to reference some things to include their socket as well, e.g. when sending a message from my player GO to the GUI or vice-versa e.g.
msg.post("default:/player#script", "attack_from_btn")

as my GUI was no longer in “default”.

Take these with a grain of salt as far as best practices go, as maybe I have some screwy design or something :smile: but hopefully it helps somebody in the same boat.

5 Likes

I noticed when using Druid, the button animations don’t work when time is paused.
Any way I can exempt them?