The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

+2 votes

so pause the game perfectly but now i can't unpause it, here is the code:

extends Spatial
var paused = false

func _process(_delta):
  if input.is_action_pressed("escape") and paused == false:
     get_tree().paused = true
     paused = true
  elif Input.is_action_pressed("ui_accept") and paused == true:
     get_tree().paused = false
     paused = false

    #please help
Godot version godot 3.3.3
in Engine by (447 points)

1 Answer

+4 votes
Best answer

Pausing is an unrecoverable state. You can't run an instruction to unpause because it's paused.

The way round this is to go into the node and change the mode. You can do this in the editor or you can hit pause_mode = Node.PAUSE_MODE_PROCESS

So, if you set this to "inherit", it's inherit the pause state. If it's "process" though it'll carry on processing even if everything else is paused.

Here's a tutorial:

by (2,159 points)
selected by

I tried that, but because it's the main scene whenever I change it to process, nothing is paused

Sorry - it's late now where I am, I'll try to come back to you tomorrow. If you can flesh out what exactly you tried that would be super helpful. The trick is to keep a script ticking over like setting an alarm clock. Don't worry if you're struggling, this is infinitely doable.


Ok, I just make a test project and it works fine. My test project looks like this:

  Spatial --> Script A
  MeshInstance ---> Script to make it move up and down

Script A:

extends Spatial

var paused = false

func _ready():
    pause_mode = Node.PAUSE_MODE_PROCESS

func _process(_delta):
    if Input.is_action_pressed("escape") and paused == false:
        paused = true
        get_tree().paused = true
    elif Input.is_action_pressed("escape") and paused == true:
        get_tree().paused = false
        paused = false

Pressing escape pauses and unpauses. Putting it in func _input would be a bit better btw.

Good luck!

ok, i will try this

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.