Control and its parent responding to keypress

Godot Version

4.5.1

Question

Hello everyone,

My main scene setup is a Node2D that contains the game area, and under it is a CanvasLayer with the GUI. One of the GUI components is the game’s help screen which can be brought up from within the game (without going to the main menu). This help screen is an instance of a scene, hidden until called for.

I use the Escape key to get out of GUI screens, but also to go to the main menu from the game screen. My problem is this:

  1. Play in the main game screen.
  2. Click the button to show the help screen.
  3. Click Escape to return to the game.
  4. Both help screen and the game react to the Escape key, and the game switches to the main menu instead of returning to the game.

I can’t seem to find a way to react to the Escape key only in the help screen when it’s shown. Played around with the focus properties and others but no dice.

Thank you for any help!

You may be able to use _unhandled_input, this walks from the bottom of the tree to the top and stops inputs when they are “handled”, to mark as “handled” you must use get_viewport().set_input_as_handled() within the function.

1 Like

Works like a charm! Thank you very much, I appreciate it.

For posterity: changed the _input function of the help screen scene to _unhandled_input, and in the game scene function that listens to the help window closing signal, add get_viewport().set_input_as_handled().