0
\$\begingroup\$

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: enter image description here

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()
\$\endgroup\$

1 Answer 1

0
\$\begingroup\$

Have you checked if _input() itself is being called? Sometimes overlaying nodes can consume inputs. Thats's all I can see based on what you've given, more information about your scene configuration would also be useful.

\$\endgroup\$
4
  • \$\begingroup\$ print("Catching resume") inside input check is being called. I also tried to use the parent node to handle this action, with the same result. UPD: added more context to the question. \$\endgroup\$
    – Maria
    Commented Sep 8 at 18:44
  • \$\begingroup\$ I don't see any obvious errors in the context you've provided so you've probably got an obscure bug. So, short of getting your entire project, I don't think I can help much. Maybe work with the debugger to see what happens line by line before and after the signal is emitted. You're also messing with scene tree pausing and changing processing modes which might be making things screwy with signals; try isolating the problem by commenting out all the game pausing logic. \$\endgroup\$
    – SlavaCat
    Commented Sep 9 at 2:46
  • \$\begingroup\$ I don't think I'm messing with the processing tree: this behavior is following the official docs for pause menu implementation. I will update this question as soon as the answer is found. \$\endgroup\$
    – Maria
    Commented Sep 9 at 13:55
  • \$\begingroup\$ In your menu_handler.gd you call scene_tree.paused = true. In the docs it says: Several things happen when a node stops processing. The _process, _physics_process, _input, and _input_event functions will not be called. So I'm not sure how you got the print statement to work. \$\endgroup\$
    – SlavaCat
    Commented Sep 9 at 23:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .