Should I use hide()/show() and/or process_mode to stop node?

Godot Version

4.3

Question

I’m making a minigame for my game that can be paused, and I was wondering how exactly hide()/show() work. What exactly is the underlying code or these and do these functions automatically set the process mode to disabled (or something similar), or do I still need to set it manually?

They set the visibility only. equivalent to visible = true/false

You will still need to modify process mode if that’s what you need.

1 Like

in godot, you have a built-in way of pausing.

each node has a process mode that is set to inherit by default, meaning they will have the same mode as the parent node.
the root node is usually set to pausable, so all nodes are pausable.
you need a node with children, preferably a scene, where you set the first node to when_paused or always, so the children will inherit these. one common case is a menu that is displayed when the game is paused.
then you can do:

get_tree().paused = true

this pauses the game. so, you show your whenPaused scene (a menu or a single button) and then pause, and you will be able to do things there while the background is paused.
make sure to set nodes that must always run to always, like something that holds score that must be read by both the menu and the game.

you can also set a node to process mode disabled to prevent all process from happening, this is usually changed by code during game.

I’m kind of new to Godot, does get_tree().paused = true pause the entire game then, or just the node that the script is attached to?

It pauses the entire game, but each node can dictate how they react to being “paused” by their process_mode

  • 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.

As per the docs jesusemora posted.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.