Up to date

This page is up to date for Godot 4.0. If you still find outdated information, please open an issue.

Pausing games and process mode

Introduction

In most games it is desirable to, at some point, interrupt the game to do something else, such as taking a break or changing options. Implementing a fine-grained control for what can be paused (and what cannot) is a lot of work, so a simple framework for pausing is provided in Godot.

How pausing works

To pause the game the pause state must be set. This is done by assigning true to the SceneTree.paused property:

get_tree().paused = true

Doing this will cause two things. First, 2D and 3D physics will be stopped for all nodes. Second, the behavior of certain nodes will stop or start depending on their process mode.

Note

The physics servers can be made active while the game is paused by using their set_active methods.

Process Modes

Each node in Godot has a "Process Mode" that defines when it processes. It can be found and changed under a node's Node properties in the inspector.

../../_images/pausemode.webp

You can also alter the property with code:

func _ready():
    process_mode = Node.PROCESS_MODE_PAUSABLE

This is what each mode tells a node to do:

  • Inherit: Process depending on the state of the parent, grandparent, etc. The first parent that has a non-Inherit state.

  • Pausable: Process the node (and its children in Inherit mode) only when the game is not paused.

  • WhenPaused: Process the node (and its children in Inherit mode) only when the game is paused.

  • Always: Process the node (and its children in Inherit mode) no matter what. Paused or not, this node will process.

  • Disabled: The node (and its children in Inherit mode) will not process at all.

By default, all nodes have this property in the "Inherit" state. If the parent is set to "Inherit", then the grandparent will be checked and so on. If a state can't be found in any of the grandparents, the pause state in SceneTree is used. This means that, by default, when the game is paused every node will be paused. Several things happen when a node stops processing.

The _process