Godot Version
4.5.1 stable Windows 11
Question
So I have my player CharacterBody2D, and its child is a Camera2D, and under that Camera2D I have all my UI nodes, for example:
I’m trying to implement controller support, and I’ve gotten to testing it for in-game menus, and it’s worked for the pause menu, I can focus the options in that fine. But my inventory tree (shown above) is supposed to have TextureRect children which, when focused, show a description of what the item does. This functionality already works with mouse.
Problem is, the inventory items don’t seem to be grabbing focus no matter what I do. Their focus mode is set to “all”, and it’s not as simple as defining their neighbours, because everytime the player gets or loses an item, the inventory is updated, and all the TextureRect children of PriorityInventory, WeaponInventory and PassiveInventory are deleted and re-created.
Why are the TextureRect inventory items unable to obtain focus? How can I fix this? Any help is appreciated.
Are you relying on the built in focus neighbor detection for controller?
I am, I didn’t know there was an alternative, but I’d like to continue on with whatever takes the least development time.
There isn’t an alternative besides setting the neighbors yourself. I’m having a hard time telling which part of the screenshots show the TextureRects you are having issues with, I don’t see a grid anywhere.
The grid is this:

And the TextureRect is this:

Do you have a way for the one of the TextureRects to grab focus initially? A controller cannot grant a node focus by clicking on it like a mouse could.
If I make it grab_focus() when the game is paused and the pause menu shows up, I can’t transfer focus from it to the buttons in the pause menu. Not to mention, I don’t want the inventory items to be the first thing focused everytime a menu opens in game.
As long as any button grabs focus, the player will be able to use the controller to navigate to the inventory items - the initial focus doesn’t need to be on an inventory item. You might have to explicitly set the neighbors either in the editor or in your code to get the navigation to work the way you want (and to avoid losing focus if the player presses the controller sideways or something).
1 Like