how to un-pause Game

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By umma

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
:bust_in_silhouette: Reply From: DaddyMonster

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:

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

umma | 2022-01-18 21:18

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.

Night!

DaddyMonster | 2022-01-18 23:01

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

Spatial
  Spatial --> Script A
  Camera
  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!

DaddyMonster | 2022-01-19 15:34

ok, i will try this

umma | 2022-01-20 02:28