Search Unity

Gamepad / Keyboard navigation with UIBuilder

Discussion in 'UI Toolkit' started by Le_Jo, Jun 7, 2022.

  1. Le_Jo

    Le_Jo

    Joined:
    Jan 24, 2019
    Posts:
    13
    Hello,


    We're having troubles with UIBuilder. The gamepad/keyboard navigation on this menu isn't under control T-T



    When we move sticks/arrows, it just keep going on the first line and if you move HARDCORE MODE the stick, sometimes, you manage to go on ON / OFF...

    Is their a proper way to make the paths ?


    Thanks,
    Joé
     
  2. uBenoitA

    uBenoitA

    Unity Technologies

    Joined:
    Apr 15, 2020
    Posts:
    220
    Hi Le_Jo,

    2-D gamepad navigation works using a simple algorithm that tries to find navigable elements in straight horizontal or vertical lines. Sometimes that's not exactly what you'll want. For customization of navigation, you can't edit anything visually, but you can do a bit of remapping though code:

    Code (CSharp):
    1. myElement.RegisterCallback<NavigationMoveEvent>(e =>
    2. {
    3.    switch(e.direction)
    4.    {
    5.      case NavivationMoveEvent.Direction.Left: myElementOnTheLeft.Focus(); break;
    6.      case NavigationMoveEvent.Direction.Top: myElementOnTheTop.Focus(); break;
    7.      // etc.
    8.    }
    9.    e.PreventDefault(); // Stop navigation from selecting the default elements it normally would
    10. });
    I know it's not the easiest way to work, we do have plans to have some integration in the UI Builder one day, but in the meantime this is the only way you can do it.