Arrow-key / gamepad focus traversal between focusable elements in a panel — Unity's built-in focus ring. Luna's role is to keep it usable when multiple views are layered: by auto-disabling the interactable elements of views underneath the active one, the focus ring can't wander off into hidden UI.
Not to be confused with Navigation, Luna's screen push/pop stack. Focus Navigation = arrow keys moving the highlight between buttons within a view. Navigation = pushing a new view onto the stack.
See the Disable Other Views On FadeIn field in UIView or UIViewComponent.
Out of the box, UITK's focus ring has no concept of layered views: a screen sitting behind your modal keeps all of its elements focusable, so arrow keys or a gamepad can walk the highlight onto buttons the player can't see or shouldn't press. When a view with Disable Other Views On FadeIn fades in, Luna's input blocking closes that gap:
pickingMode = Ignore + focusable = false — removed from both pointer picking and the focus ring in one move, so neither mouse clicks nor controller traversal can reach behind the active view.SetEnabled(false), no :disabled USS rules fire — nothing behind the modal greys out mid-fade.pickingMode is snapshotted at block time and restored exactly when the view fades out. Already-blocked elements are not re-snapshotted, so stacked modals unwind correctly: closing the inner modal returns focus to the outer modal, not to the screen underneath both.UI Toolkit has one :focus for every kind of focus. A button keeps it after a tap, and a screen that focuses its first button as it opens gives it one too, so a focus ring keyed on :focus also sits on the last thing clicked. LunaFocusVisible tells the two apart and stamps the luna-focus-visible class (LunaFocusVisible.ClassName) on the focused element only when the player should see the focus:
Focus(), a popup landing on its first choice, focus restored after a pop) while the last input was navigation: a move, Submit or Cancel. Before any input, a gamepad control scheme counts as navigation, and so does a switch to a gamepad.The class goes on blur and on any pointer press, and a key or button pressed while a tapped element keeps focus puts it on that element. At most one element carries it.
Key a focus look on the class, never on :focus: Luna's button looks, the UI Effects hover-on-focus and the luna-fx-btn forwarders do.
.menu-row.luna-focus-visible,
.menu-row.luna-focus-visible:enabled {
border-color: var(--focus-ring);
}Installing. One handler per panel. LunaUIManager installs it on the panel of every view it registers, and every HoverFocusManipulator on the panel of its target. For a panel Luna does not manage, call it once with any element in that panel:
LunaFocusVisible.Install(root);From code. LunaFocusVisible.IsVisible(element) reads the mark. A HoverFocusManipulator subclass reads IsFocusVisible and overrides OnFocusVisibleChanged(), which runs when the mark comes or goes while focus stays (a pointer press after a gamepad focus). Any element can listen for the same moment with FocusVisibleChangedEvent (IsVisible); a focus change itself sends no such event, because the mark is already set when the element's FocusEvent or BlurEvent runs.
Each UI Toolkit panel features a focus ring that determines the focus order of elements. You can learn more about this feature here:
Unity: Dispatch Events (opens in new tab)
You can manually determine what element is focused next.
myVisualElement.RegisterCallback<NavigationMoveEvent>(e =>
{
switch(e.direction)
{
case NavigationMoveEvent.Direction.Up: U.Focus(); break;
case NavigationMoveEvent.Direction.Down: D.Focus(); break;
case NavigationMoveEvent.Direction.Left: L.Focus(); break;
case NavigationMoveEvent.Direction.Right: R.Focus(); break;
}
e.StopPropagation(); // Prevent further processing of the event
myVisualElement.focusController.IgnoreEvent(e); // Prevent default navigation
});Settings
Theme
Light
Contrast
Material
Dark
Dim
Material Dark
System
Sidebar(Light & Contrast only)
Font Family
DM Sans
Wix
Inclusive Sans
AR One Sans
Direction