Need help with controlling main menu buttons with a gamepad

Godot Version

v4.2.2.stable.official.15073afe3

Question

I’ve followed two tutorials on how to make a UI system that can be controlled with a gamepad, but nothing’s working. Why could this be? Also, please let me know if any additional information is needed. (Note that Focus modes are set to “All” for all buttons, and their neighbors all set.)

Images

Scene Tree:

2D Scene:


(The buttons are “PLAY,” “minigames,” “settings.”)

Script (attached to root node):

extends Control

func _ready():
	$"VBoxContainer/Play Button".grab_focus()

Input Map:

Sometimes with focus you have to defer:

func _ready():
    $"VBoxContainer/Play Button".call_deferred("grab_focus")

Does gamepad navigation work once focus is set? That is, once you’ve clicked a button with the mouse (which will give it focus) can you move focus with the gamepad?

1 Like

I just tried your code and I also tested to see if the gamepad would work after clicking on a button with mouse. Both do not work.

Is there some visual indication of which button has focus?

If one of the buttons has focus, Godot should move that focus around based on gamepad input, but it doesn’t do “press”; you have to handle that yourself. In my code, I’ve got something like:

# This would be on VBoxContainer in your scene, probably?

func _process(delta: float) -> void:
    if Input.is_action_just_pressed("GUI Select"):
        for entry: Node in get_children():
            if entry.has_focus():
                match(entry.name):
                    "Play Button":      _activate_play()
                    "Minigames Button": _activate_minigames()
                    "Settings Button":  _activate_settings()
1 Like

This helped me, thanks. Turns out I just assumed that it would use the hover texture, not realizing that I had to set a separate focus texture.

1 Like