Quick start
This gets a UI Toolkit screen working with a gamepad and a keyboard in about five minutes.
1. Install
Section titled “1. Install”In Window > Package Manager, choose + > Add package from git URL and enter:
https://github.com/TasmiinaCode/UnityUIFlow.git?path=/Packages/com.tasmiinacode.uiflowThe 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.
2. Check the scene’s event system
Section titled “2. Check the scene’s event system”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.
3. Add the UIFlow Document component
Section titled “3. Add the UIFlow Document component”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.
4. Show focus only when it matters
Section titled “4. Show focus only when it matters”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;}5. Fix what the search doesn’t guess
Section titled “5. Fix what the search doesn’t guess”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.
Without the component
Section titled “Without the component”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 VisualElementnavigator.FocusEntryElement();// laternavigator.Detach();Next steps
Section titled “Next steps”- Concepts explains how a move is decided, so you know which tool to reach for.
- Troubleshooting and FAQ covers the common surprises.