avatarDaniele Quero, PhD

Summary

The web content explains how to implement and utilize button navigation within Unity's UI system for improved user interaction.

Abstract

The article titled "Unity UI Button Navigation Explained" provides a comprehensive guide on how to set up button navigation in Unity's UI system. It outlines the three methods of interaction with UI buttons: mouse clicks, touchscreen taps, and key presses when a button is selected. The navigation can be configured using the Inspector window, with six navigation options available: None, Horizontal, Vertical, Explicit, Automatic, and Everything. These options determine the selection order of buttons when navigating with a keyboard or gamepad. The article emphasizes the importance of understanding these navigation types to enhance user experience, suggesting horizontal navigation for menu bars and vertical navigation for main menus. It also highlights the flexibility of Explicit navigation, which allows developers to define a precise navigation order, and the convenience of Automatic navigation for simpler UI layouts. Visual aids, such as arrows and in-game screenshots, are provided to illustrate the concepts, and a link to further reading on selecting the first button without requiring a click is included. The author encourages readers to support their work by clapping for the article, sharing it, and considering a Medium membership.

Opinions

  • The author believes that understanding the differences between navigation options is crucial for creating an intuitive user interface.
  • Explicit navigation is considered the most flexible option for complex UI designs, allowing for precise control over button selection order.
  • Automatic navigation is recommended for straightforward UI layouts but may not be suitable for complex or irregular designs.
  • The author values the importance of visual feedback for developers, providing images and GIFs to demonstrate navigation paths.
  • The author suggests that the first button should be selected by default to improve navigation flow, referencing additional reading on the topic.
  • Support for the author's work is encouraged through article engagement and Medium membership, indicating a desire for community involvement and recognition of their contributions.

How to Unity

Unity UI Button Navigation Explained

Learn how and why to implement the button navigation

Within Unity’s UI system, buttons can be accessed and interacted with in three ways:

  1. click them with the mouse
  2. tap them on a touchscreen
  3. pressing a key (gamepad or keyboard) when they are selected.

To set the button navigation for a UI button in Unity, you can use the Navigation panel in the Inspector window.

There are six button navigation options that determine the order in which buttons are selected when the user navigates the UI using a keyboard or gamepad:

  1. None: the buttons cannot be selected using the keyboard or gamepad navigation.
  2. Horizontal: the buttons will be navigated from left to right or vice-versa. When the user reaches the end of a row, they will move to the next one.
  3. Vertical: the buttons will be navigated from top to bottom or vice-versa. When the user reaches the end of a column, they will move to the next one.
  4. Explicit: the order in which the buttons are selected is explicitly defined by the developer. The developer can specify the order in the Navigation panel of each button’s Inspector, using the “Up”, “Down”, “Left”, and “Right” fields to define the next button in each direction.
  5. Automatic: Unity calculates the next selectable element based on the UI layout.
  6. Everything: allows navigation between different UI elements, for example from buttons to also text inputs, drop-down menus…

Clicking on the Visualize button will make appear arrows connecting the buttons, showing the available navigation paths according to the chosen option.

Horizontal Navigation: it is possible only to move left-right or right-left, up and down keys will not work.
Vertical Navigation: it is possible only to move up-down or down-up, left and right keys will not work.

To improve the user’s experience, it is crucial to understand the differences between the navigation options and choose the most appropriate one for each UI element. For instance, horizontal navigation may be suitable for a menu bar, while vertical navigation might be better for a main menu.

Up, down, left, and right navigation is precisely defined by you

Explicit navigation is the most flexible option, allowing developers to define the order of buttons precisely. This is especially important for complex UIs. You just need to drag and drop the next item onto the “Select On [Up/Down/Left/Right]”… and, of course, do it for every other button!

When Automatic navigation is chosen, Unity will look for other elements right, down, left, and then up, in that order, to define the best path. This option can be useful for simple UIs with consistent and predictable layouts. However, in more complex UIs or ones with irregular layouts, the automatic navigation may only sometimes result in the desired order.

It’s also important to note that automatic navigation only works for elements that share the same parent.

Here is how the (vertical) navigation appears in-game, for visibility, selected buttons are red.

Did you notice that I needed to click the first button in order to select it and move on with the keys?

See here to learn how to navigate without having to press a button first.

If you liked the article, please clap to it and share it! Also, take a look at my games!

Get access to my stories and those of other Medium writers for just $5 a month. With no additional cost to you, I will receive half of your payments as a commission: it’s a great way to support me!

Join my newsletter and receive regular notifications when I post.

Unity3d
Unity Ui
Unity2d
Unity Game Development
Recommended from ReadMedium