Help with pause menu

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

ok so I have a main menu and a pause menu but the problem is I can pause in the main menu. How do I fix this?

(pause menu code)

extends Control

func _process(delta):
if Input.is_action_pressed(“ESC”):
visible = true
get_tree().paused = true

func _on_Continue_pressed():
hide()
get_tree().paused = false

func _on_Main_menu_pressed():
visible = false
get_tree().paused = false
get_tree().change_scene(“res://Menu.tscn”)

func _on_quit_pressed():
get_tree().paused = false
get_tree().quit()

:bust_in_silhouette: Reply From: Gluon

Is your pause menu set as autoload? The easiest thing would be to not autoload it and just add an instance of the pause scene to any scenes you do want it to operate in.

If you really want it to autoload you could have a boolean in your pause menu which is set on _ready function of each scene loaded to true or false depending on if the pause should operate there or not then change the pause menu code like

func process(delta):
if NewBoolean and Input.isactionpressed("ESC"):
visible = true
gettree().paused = true
:bust_in_silhouette: Reply From: timothybrentwood

You can make your escape key function as a pause and unpause:

func _process(delta):
    if not Input.is_action_just_pressed("ESC"):
        return # do nothing if escape isn't pressed
    elif visible: # we are paused
        visible = false
        get_tree().paused = false 
    else: # we are unpaused
        visible = true
        get_tree().paused = true