My menu opens fine with the below code, adds the open menu to the array, increasing it's size to 1. I do this so the close menu button will close the last menu opened first, working back. But after the first menu is opened, pressing the key (Esc) does nothing. Not even a print statement. Why is that, since the array size is no longer less than 1...?



func _input(event):
	if event.is_action_pressed("ui_game_menu"):
		print(open_menus)
		get_open_menus()
		print("size is: ", open_menus.size())
		if open_menus.size() < 1:
			var game_menu = load("res://UI/Game Menu.tscn").instance()
			add_child(game_menu)
			get_open_menus()
			print("size is: ", open_menus.size())
		else:
			print(open_menus[-1])
			open_menus[-1].queue_free()


func get_open_menus():
	open_menus = []
	for child in get_tree().get_nodes_in_group("menu"):
		if not self.is_a_parent_of(child):
			continue
		open_menus.append(child)
		print(open_menus)
	return open_menus```
  • Ok... So feeling like an idiot here. Apparently I set the menu to process when the tree is paused (which happens when the menu opens), but did NOT set the GUI canvas layer to process. So, when the menu opened and the game world paused, so did the GUI. And that's why it wasn't receiving the Esc key input...

    Thanks so much for your attempts at helping me, especially cyberreality for the steady feedback. Sorry it was something so silly that I overlooked.

Do you get any errors or warning in the console on the bottom?

    What kind of Node is the menu? It's likely it is grabbing the input focus and thus your main script won't work. You can either disable (pass) input from the menu or handle the escape/close in the menu itself. I think handling the escape in the menu would make more sense, and also scale better to multiple menus (provided they can't be refocused like an OS, meaning they act as modals). Otherwise you'd have to look at the mouse flags, I think setting it to pass will move it to the next script, which will be the script you posted.

      cybereality

      The script is in my Canvas Layer GUI, and the menu is a Control node child instanced to open. Seems I have to do more reading on focus (and mouse flags?)

      The buttons inside the menu grab focus, and I never realized that could mean all input to other control nodes would be lost (though it makes sense since only one node can have focus). That's probably the case then.

      Can I ask to clarify something? If it's one of the buttons inside the menu that has focus, does that mean each button should have the code (they are all instances of a single basic button scene, so that's not the issue, just want to understand) to handle the escape/close because the root of the scene won't ever receive it? The menu root never has focus. Something like the focused button emitting a signal to the menu root?

      Sorry, I'm still learning a lot. And it seems something that seems as obvious as 'if -> else' isn't always so clear.

      Cunningly, the buttons in question are inside the PlayerMenuButtons VBox. Though I suppose that's pretty obvious.

      godotDcoding
      Esc is the key in question, and I print a statement in both the 'if' and 'else'
      So it should print something either way, but after the menu opens, it doesn't print (respond) at all anymore to the Esc key.

      I haven't had a chance to test it yet, but I think cybereality is probably onto something. I probably won't get to test it until tomorrow though. But I will read through your link in the meantime. Thank you!

      Ok... So feeling like an idiot here. Apparently I set the menu to process when the tree is paused (which happens when the menu opens), but did NOT set the GUI canvas layer to process. So, when the menu opened and the game world paused, so did the GUI. And that's why it wasn't receiving the Esc key input...

      Thanks so much for your attempts at helping me, especially cyberreality for the steady feedback. Sorry it was something so silly that I overlooked.