Pause & Continue in Godot

Well, it is time to use pause in Godot and after a little research you find the magic get_tree().paused method. And… it is not working! But why? Your game is successfully pauses, but you cannot make it leave that state. Maybe the method is not working? No, it is okay. You just forgot about a little detail: every node pauses simultaneously, so no one is listening for your key presses. You should allow one node, where your pause logic is, to be free from pausing. Sound wage? Then let’s go into the details!

Suppose you have three nodes: Main (Node), Character (Sprite2D) and GameManager (Node).

Main is a parent for the rest two nodes:

In Character, we added rotation just to make it easier to observe pausing:

And the main logic is in GameManager node’s script, to separate it from other nodes, because it need to run in any circumstances. Here I added is_paused variable to toggle between pause and continue states using one single Esc key and bind it to “pause” Input action:

And, which is the most important I change GameManager node’s Process mode to Always, to make it run even when the game and all other nodes are paused:

Now, if we run the game and press Esc key (which I connected to “pause” Input action previously) I can pause and continue the game without any problems.

That’s it! Now you know how to do it. But in case you want to have a copy of the code I’ve presented here, you can use this GitHub repository dedicated to this article. Or if you prefer video explanation then I invite watching this video on my YouTube channel. See you!

Share
Leave a Comment

Comments

No comments yet. Why don’t you start the discussion?

    Leave a Reply

    Your email address will not be published. Required fields are marked *