Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Question Rebind Focusable Navigation

Discussion in 'UI Toolkit' started by gw1108, Nov 20, 2022.

  1. gw1108

    gw1108

    Joined:
    Jan 22, 2013
    Posts:
    6
    In my basic inventory UI I can navigate through buttons using W/A, arrowkeys, and tab to navigate down. But how do I rebind these navigation options? I do not want tab and W/A keys to navigate, and I also want to add new buttons for navigation.
     
  2. gw1108

    gw1108

    Joined:
    Jan 22, 2013
    Posts:
    6
    I realize now that the "focused" was actually in the active state. Is there a page or documentation how navigation through the new unity ui builder works with arrow keys or WASD?
     
  3. dlorre

    dlorre

    Joined:
    Apr 12, 2020
    Posts:
    700
    Navigation is the "dark side" of UI toolkit. First it depends if you are using the old or the new input system. If you are on the new input system you can rebind by editing the action map. These are my settings:

    upload_2022-11-21_15-37-36.png

    You can edit the Actions Asset with some limitation, since Tab is hardcoded.

    upload_2022-11-21_15-53-15.png

    As you can see no Tab key here.

    I have chosen to disable NavigationMove events and handle them directly in my code, but I don't think it's mandatory. However as I said Tab is hardcoded and will trigger no matter what. So to bend the navigation system to your needs you have to set focusable=true on the controls you want to be available in the tab cycle and focusable=false on the others, for example if you have multiple panels.

    You have no other control on the focus controller than setting focusable = true|false. There is no way the focus controller is going to tell you which element goes next or which controls are cyclable. You have to read the focusable state of each control and make guesses or you maintain a list of the focusable controls.

    upload_2022-11-21_16-0-18.png

    Here I have 2 panels, I don't want to tab all the way to the other panel, so I have to set the 2nd panel controls to focusable = false. If I switch to the second panel then I set the first panel elements focusable=false and the second panel elements to focusable=true.

    Now there are composite elements and stuff like ScrollViews which are special and if you set focusable=true on a scrollview some funny things will occur. Overall it's quite a nightmare to work with the focuscontroller. The more recent versions of Unity like 2022 and 2023 offer some improvements like new NavigationMove events with directions, however it's still far from ideal.

    Ideally you could set for each visual element at the very least the next and previous ones, or better the left, right, top and bottom ones, and disable Tab if you wish.

    Also, it's unclear whether these events are used for Navigation between controls and navigation inside a list or a dropdown field, there is no clear distinction, this is why I have chosen to disable them.

    ETA: to answer your question more clearly the only way I know to disable the TAB key is to set every visual element to focusable=false.
     
    Last edited: Nov 21, 2022