+3 votes

Hi.
I am trying to find a way to make my in game menus compatible with a joystick.
The menu is extremely simple, just a node with Button children.
Looking at the Inspector tab of the Buttons I can see the Focus Neighbor but I cannot understand how to use them or how to make a button focused.

in Engine by (177 points)

Sorry about this, but I just found out how to do it.
To set a button focused you can use the method .grab_focus()
Afterwards everything works as expected.

Please, convert your comment into an answer, so that this won't show up in the unanswered list. (probably select it as a best answer as well.)

1 Answer

+2 votes
Best answer

Godot have from default input map some joystick input. For example uiaccept to Return, Enter, Space and Device 0, Button 0. uileft , uiright and etc.
Those actions are automatically used for ui (user interface).
So if you grab focus for a button with the method .grab
focus you can point the button which is going to be highlighted in your menu. Afterwards int the inspector tab of the Button you can assign other buttons as neighbors. Up, down, left and right neighbors. Those are the buttons which are going to grab focus when you use the default ui input map.
Also if you use containers, those containers are going to take care of those neighbors. For example you do not have to manually set up the neighbors in a grid_container.

by (177 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 Frequently asked questions and 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 [email protected] with your username.