Migrating from the default FocusController
UIFlow sits on top of UI Toolkit’s own focus system. It doesn’t replace the FocusController: it decides where a
directional move goes and then calls Focus() like your code would. Turning it on is safe to try on one screen at
a time.
What stays the same
Section titled “What stays the same”Focus(),Blur(),focusable,tabIndex,delegatesFocusandcanGrabFocuswork as before.FocusInEvent,FocusOutEvent,FocusEventandBlurEventfire as before.:focusstyles,NavigationSubmitEventandNavigationCancelEventare unchanged.- Controls that use directions themselves keep them: sliders, list views, open dropdowns, text fields being edited.
- Your own
NavigationMoveEventcallbacks on elements still run first, and can still stop the event. - Tab keeps Unity’s order unless you change
tabNavigation. - Screens without a navigator are untouched.
What changes
Section titled “What changes”| Default behaviour | With UIFlow |
|---|---|
| A move picks a target from the focus ring order and geometry. | A move picks the nearest element in the pressed direction, preferring aligned ones. |
| When nothing lies in the direction, focus wraps around the panel. | Focus stays where it is. Wrapping is per scope (horizontal-edge, vertical-edge). |
| Hidden, transparent, clipped or covered elements can take focus. | They are skipped. |
| Elements outside a modal can take focus. | A NavigationScope with trap-focus keeps focus inside. |
| When the focused element is hidden or removed, focus is lost. | Focus moves to the nearest element of the same scope. |
| A move with nothing focused starts from the first element. | It returns to the element the player left. |
| Entering a ListView focuses the list. | Entering it selects a visible row, and sideways moves start from that row. |
Code you can remove
Section titled “Code you can remove”Look for these patterns in your UI code; UIFlow does the same thing:
NavigationMoveEventcallbacks that redirect focus to a specific element. Use a link instead (SetNavigationLink,--uiflow-nav-*in USS, orNavigationLinksin UXML).- Code that calls
Focus()when a screen or a modal opens. Usefocus-on-showanddefault-focuson aNavigationScope, or callnavigator.FocusInto(screen). - Code that remembers the last focused element per screen or tab. Scopes remember it (
enter-behavior="Remembered"). - Code that sets
focusable = falseon elements while they are hidden or animating. Hidden elements are skipped; for animations UIFlow can’t detect, useSetNavigationTransitioning. - Code that puts focus back where it was when a modal closes. Use
cancel-behavior="ReturnToOrigin", and focusscope.originfrom a Close button. - Code that tracks the last-used device to switch button prompts or focus styles. Use
InputDeviceTracker.changedand theuiflow-device-*classes.
Turning it on step by step
Section titled “Turning it on step by step”- Add a
UIFlowDocumentto one screen, or callUIFlowNavigator.Attachon one part of it. - Play the screen with a gamepad. Press F9 to see where each direction goes.
- Fix the moves you don’t like with links, and wrap modals, tabs and grids in scopes.
- Remove the focus code the list above makes redundant.
- Scope your
:focusand:hoverstyles touiflow-navigatinganduiflow-device-pointer.
To turn UIFlow off again, remove the component or call navigator.Detach(). Links and scopes left in your UXML and
USS are ignored without a navigator.