8
\$\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\$
12
\$\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.

| improve this answer | |
\$\endgroup\$
  • \$\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 Sep 19 '18 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);
    }
}
| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.