0 votes

Hi, I am messing with menu in my game and cant figure out how to select buttons with pressing keys. I have a ButtonGroup and buttons in it. I found that buttons have in params Focus Neighbour so I set it up but it doesnt work... I expect that I have forgotten smt and its really noob problem so please help me out..

in Engine by (18 points)

2 Answers

0 votes

If you're looking to send focus to a control. Control objects have a method called .grab_focus()

Docs: http://docs.godotengine.org/en/stable/classes/class_control.html#class-control-grab-focus

Assuming you have a Control node with a Button node named Button as it's child:
With something like this, you can send focus by hitting any keyboard key.

extends Control

func _ready():
    set_process_input(true)

func _input(event):
    if(event.type == InputEvent.KEY):
        get_node("Button").grab_focus()
by (5,192 points)
0 votes

To use the focus neighours you have to focus on it's neighbours in a script.
Like
func _ready(): ButtonGroup.get_button_list()[0].grab_focus()
http://docs.godotengine.org/en/latest/classes/class_buttongroup.html

by (482 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.