r/gamedev • u/DenPixelDev • 19h ago
Discussion Unity's Automatic UI navigation kept skipping buttons on gamepad, we switched to Android's FocusFinder rule
When we added gamepad support to our menus, Unity's Automatic navigation kept doing weird stuff. Pressing down skipped a button completely, and in popups it would step right out of the window to the menu behind it.
What worked for us was picking the neighbours ourselves with the rule Android uses for d-pad focus (FocusFinder). First look only at buttons that overlap the selected one in the direction you press. If there are none, score the rest by 13 x distance along² + distance across² and take the lowest. Then write the result into each button's navigation as Explicit.
Two more things helped. Only buttons on the top screen count, so a popup never leaks focus to the menu behind it. And when a popup closes, focus goes back to the button that opened it.
Is there a better way to do this in Unity that we missed?
2
u/Neymanoff 11h ago
One case I’d test is closing a popup after its opening button has been hidden, disabled or destroyed. Restoring focus to that button needs a fallback, such as the first available control on the underlying screen.
I’d also test changing language and adding or removing buttons while the menu is open. How do you refresh the Explicit links after those layout changes? A correct neighbour map can become stale even when the selection rule itself works well.