9
\$\begingroup\$

Sometimes, after clicking a button created by unity's new UI Button, the button stays in its highlight state. Note that Button script has Color Tint set as it's Transition property and the Interactable checkbox is checked.

How can I solve this?

\$\endgroup\$

2 Answers 2

17
\$\begingroup\$

The Navigation property of buttons is set to Automatic by default, allowing you to navigate through buttons using arrow keys.

If you disable this by changing the Navigation property to None, buttons will not stay highlighted.

\$\endgroup\$
1
  • \$\begingroup\$ Something important to add to it: If you set the Navigation to None, you 1. can't use your keyboard or controller to navigate to/from it and 2. trying to get it with GameObject.Find will return some type of object that isn't really usable because everything about it is null. So basically: If you use None, you have to either drag the button onto a public variable in the Inspector or instantiate the button at runtime to get a functioning reference to it. Tested with Unity 2017.3.1f1. \$\endgroup\$
    – Neph
    Commented Sep 19, 2018 at 9:51
1
\$\begingroup\$

(In addition to the accepted answer, this is another answer if you are not able to set the Navigation property of buttons to None in your context.)

You can also use UnityEngine.EventSystem.SetSelectedGameObject to manually deselect the button. For example:

private void DeselectClickedButton(GameObject button)
{
    if (EventSystem.current.currentSelectedGameObject == button)
    {
        EventSystem.current.SetSelectedGameObject(null);
    }
}
\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .