Skip to content

Quick start

This gets a UI Toolkit screen working with a gamepad and a keyboard in about five minutes.

In Window > Package Manager, choose + > Add package from git URL and enter:

https://github.com/TasmiinaCode/UnityUIFlow.git?path=/Packages/com.tasmiinacode.uiflow

The Input System package is installed with it. If Unity asks to enable the new input backends, say yes and let the editor restart. Project Settings > Player > Active Input Handling must be Input System Package or Both.

Runtime UI Toolkit reads the Input System by itself, so a scene with only UI Toolkit needs no EventSystem. If the scene has one (because it also uses uGUI), its input module must be the InputSystemUIInputModule: UI Toolkit then gets its input through it.

Select the GameObject that has your UIDocument and click Add Component > UI Toolkit > UIFlow Document.

That’s all. Press Play:

  • The first focusable element in the top-left takes focus.
  • The d-pad, the left stick and the arrow keys move focus to the element that looks nearest in that direction.
  • A (Enter) presses buttons, B (Esc) is Cancel.
  • The right stick scrolls the ScrollView around the focused element.
  • Press F9 to see the debug overlay: every focusable element, where each direction goes, and why other elements were rejected.

Unity’s default theme shows a focus outline all the time. With a gamepad that’s what you want; after a mouse click it usually isn’t. UIFlow puts a class on the panel root for the device the player uses last, so you can scope your focus styles:

/* Focus ring only while the player navigates with a gamepad or keyboard. */
.uiflow-navigating .menu-button:focus {
border-color: #ffd34d;
scale: 1.05;
}
/* Hover only while the player uses a mouse, so a resting cursor doesn't show a second highlight. */
.uiflow-device-pointer .menu-button:hover {
background-color: #3a4a5a;
}

Most layouts work as they are. When one move goes somewhere you don’t want, override it:

/* In USS: Down from Quit goes back to the top. */
#Quit {
--uiflow-nav-down: "#Continue";
}
// Or from code.
quitButton.SetNavigationLink(NavigationMoveEvent.Direction.Down, "#Continue");

For modals, tabs and grids, wrap the elements in a NavigationScope:

<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uiflow="UIFlow">
<uiflow:NavigationScope name="ConfirmDialog" trap-focus="true" cancel-behavior="ReturnToOrigin"
focus-on-show="true" default-focus="#Cancel" style="display: none;">
<ui:Button name="Confirm" text="Delete" />
<ui:Button name="Cancel" text="Keep" />
</uiflow:NavigationScope>
</ui:UXML>

Showing the dialog (display: flex) moves focus into it, focus can’t leave it, and Back returns focus to the button that opened it. Your code only shows and hides it.

To attach UIFlow from code, for example to a panel you build yourself or to one part of a screen:

using UIFlow;
var navigator = UIFlowNavigator.Attach(root); // any VisualElement
navigator.FocusEntryElement();
// later
navigator.Detach();