I'm making a game where I want an ingame notification to pop up when the player moves to the next area. The notification has two buttons, "ok" and "cancel", and I want the user to be able to switch between the buttons using keyboard/controller input. I found out about the function grab_focus, which I've used in my main menu script where it works normally. However when I try to use the same function while the game is running, I seem to be unable to select the button. I imagine this has to do with the player input somehow, but I have no clue how to fix it. Does anyone know any solutions? Here's my CanvasLayer notification code, in case it helps:
extends CanvasLayer
@onready var UIManager : Node = get_parent()
@onready var ok_button : Node = $VBoxContainer/Ok
func _ready():
ok_button.grab_focus()
ok_button.pressed.connect(_on_ok_button_pressed)
# Hide the popup if the escape button is hit
func _input(event):
if event is InputEventKey and visible:
if event.pressed and event.keycode == KEY_ESCAPE:
UIManager.toggle_visibility(name)
func _on_ok_button_pressed():
UIManager.toggle_visibility(name)
PS The part with the UIManager can be ignored, in this case it does the same as hide()