• Godot Help
  • Can't grab focus when input come from a gamepad?

Hi,
Have some trouble with Control nodes and grab_focus() :

I have a TabContainer with 3 TabBar children.
When i click on a TabBar at runtime, i call grab_focus() on the first element (button) in the tab

While it works with a mouse (The first button get focused), when i change tab with the gamepad, the grab_focus() is called the same way with the mouse input, but the button doesn't grab focus.

Am i missing something? Thank you

  • For the exact same code when i selected the tab with the mouse the button grab the focus just fine, but with the gamepad the button didn't grab focus at all, get_viewport().gui_get_focus_owner() stayed null.
    So what i ended-up doing:

    func _process(delta):
        if get_viewport().gui_get_focus_owner() == null:
           if not item_in_shop.is_empty():
    	  item_in_shop[0].button.grab_focus()

    It's working fine now. I don't understand why it's not working without it tho

For the exact same code when i selected the tab with the mouse the button grab the focus just fine, but with the gamepad the button didn't grab focus at all, get_viewport().gui_get_focus_owner() stayed null.
So what i ended-up doing:

func _process(delta):
    if get_viewport().gui_get_focus_owner() == null:
       if not item_in_shop.is_empty():
	  item_in_shop[0].button.grab_focus()

It's working fine now. I don't understand why it's not working without it tho