I have the following pause menu script:
signal resume_game_signal
const MARGIN_BOTTOM = 100
const MAIN_MENU_PATH = "res://Scenes/GUI/main_menu.tscn"
func _ready():
_setup_margin_container()
func _input(event):
if event.is_action_pressed("ui_cancel"):
print("Catching resume")
resume_game_signal.emit()
func _setup_margin_container():
marginContainer.add_theme_constant_override("margin_bottom", MARGIN_BOTTOM)
func _on_ResumeButton_pressed():
resume_game_signal.emit()
func _on_ToMainMenuButton_pressed():
get_tree().change_scene_to_file(MAIN_MENU_PATH)|
resume_game_signal.emit()
works inside of _on_ResumeButton_pressed()
. print("Catching resume")
is being called on button press. resume_game_signal.emit()
doesn't work inside _input(event)
.
I'm struggling to understand why; any debugging ideas are welcomed.
More context. Scene hierarchy:
menu_handler.dg
extends Node
var pause_menu = null
var pause_menu_shown = false
# Called when the node enters the scene tree for the first time.
func _ready():
_hide_pause_menu()
func _input(event):
if event.is_action_pressed("ui_cancel"): # "ui_cancel" is Esc by default in Godot
if !pause_menu_shown:
_show_pause_menu()
func _show_pause_menu():
if pause_menu == null:
var pause_menu_scene = preload("res://Scenes/GUI/pause_menu.tscn")
pause_menu = pause_menu_scene.instantiate()
pause_menu.resume_game_signal.connect(_resume_game)
add_child(pause_menu)
get_tree().paused = true
pause_menu.show()
pause_menu_shown = true
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
func _hide_pause_menu():
if pause_menu:
pause_menu.hide()
get_tree().paused = false
pause_menu_shown = false
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
process_mode = Node.PROCESS_MODE_INHERIT
func _resume_game():
_hide_pause_menu()