How to pause / resume the game including physics?

Hi Community,

I am very new to this engine, just read the tutorial and downloaded templates and examples.

I try to find out, how to pause the game (for example, by pressing escape button), so that screen is still displayed, but physics and keyboard interactions for the scene are stopped. And then, by pressing escape again, scene is resumed. How to implement it?

Hello! For physics you can set the time scale to 0.0 using this node:

Captura de tela de 2021-02-14 19-40-12

Depending on the logic envolved, you should pause the trait (except the one responsible for the menus)

Captura de tela de 2021-02-14 19-42-43

You can use an On Event node to pause the trait, but after paused, you can’t “resume” it back because it would be paused… You should resume the paused traits trought an active trait. For this you should store all paused traits in a list (array) and loop trought this array in the active trait.

A simpler way (not better because of performance) would be to branch the update method of each trait sensible for the paused state:

These are just ideas, probably there are a lot of ways to do this to work. Also as a pause state is common in all games, maybe there should have a checkbox for traits that should not be updated when the global state “paused” is true… If you don’t find a feasible way to do that, feel free to open a feature request here.

3 Likes