Skip to content

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.

  • Focus(), Blur(), focusable, tabIndex, delegatesFocus and canGrabFocus work as before.
  • FocusInEvent, FocusOutEvent, FocusEvent and BlurEvent fire as before.
  • :focus styles, NavigationSubmitEvent and NavigationCancelEvent are unchanged.
  • Controls that use directions themselves keep them: sliders, list views, open dropdowns, text fields being edited.
  • Your own NavigationMoveEvent callbacks 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.
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.

Look for these patterns in your UI code; UIFlow does the same thing:

  • NavigationMoveEvent callbacks that redirect focus to a specific element. Use a link instead (SetNavigationLink, --uiflow-nav-* in USS, or NavigationLinks in UXML).
  • Code that calls Focus() when a screen or a modal opens. Use focus-on-show and default-focus on a NavigationScope, or call navigator.FocusInto(screen).
  • Code that remembers the last focused element per screen or tab. Scopes remember it (enter-behavior="Remembered").
  • Code that sets focusable = false on elements while they are hidden or animating. Hidden elements are skipped; for animations UIFlow can’t detect, use SetNavigationTransitioning.
  • Code that puts focus back where it was when a modal closes. Use cancel-behavior="ReturnToOrigin", and focus scope.origin from a Close button.
  • Code that tracks the last-used device to switch button prompts or focus styles. Use InputDeviceTracker.changed and the uiflow-device-* classes.
  1. Add a UIFlowDocument to one screen, or call UIFlowNavigator.Attach on one part of it.
  2. Play the screen with a gamepad. Press F9 to see where each direction goes.
  3. Fix the moves you don’t like with links, and wrap modals, tabs and grids in scopes.
  4. Remove the focus code the list above makes redundant.
  5. Scope your :focus and :hover styles to uiflow-navigating and uiflow-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.