I’ve made a UI button with its transition state set to Tint and I can click it and call a function from its OnClick() event list. It generally seems to work as expected except for one small visual annoyance; after clicking the button, it remains in its highlighted state until I click somewhere else in the scene.
Anyone know why the button will not automatically return to the Normal Color tint after the button is clicked and instead stays stuck on the Highlighted Color state?
Or, does anyone know which class I can use to grab a reference to the button from inside the script being called from the OnClick() event list so I can force the UI button back to its default state?
Change the navigation to ‘none’ on the button component, it’s a bug with Unity’s keyboard menu navigation.
2025 and the problem is still there, nowhere on the internet did I find the solution to it (including ChatGPT) and none of the solutions worked, until I stumbled upon this checkbox on the Animator component that fixed it!
Let me explain:
In the early days of UGUI (Unity 5, 2017, 2018) there were four transition states:
“Normal”, “Highlighted”, “Pressed” and “Disabled”
In Unity 2019 a new state was introduced: “Selected”
The selected state is used for non-pointer-input (gamepad or keyboard). It is used as an indicator for the selectable that is currently focused.
The annoying part: When you click on a button, it becomes the selected one which feels just wrong for mouse and touch input, as it will transition to the “Selected” state and remains in that state.
For touch, this is easy to fix: Just make the “Selected” state the same as “Normal”.
For mouse, this hack also works but is not perfect as the “Selected” state would not ever transition to “Highlighted”.
You could help yourself in code: In the callback of the button, call myButton.OnDeselect(null) - or, to be more general, write a method that can be used from anywhere without knowing the selected element:
public static void DeselectCurrentUiElement()
{
EventSystem.currentSelectedGameObject?.GetComponent<Selectable>()?.OnDeselect(null);
}
If you don’t want to add a callback to a OnDeselect-method everywhere, you can either downgrade to Unity 2018 or wait for Better UI 3.0 which I will release soon (hopefully). This will allow you to disable the selected-state-behavior for pointer input.
I found a solution that worked for me.
You need to remove the sprite from Selected Sprite. I think Unity bugs out when pressing the button and sometimes leaves it SELECTED which is why it lights up still.
Just set Selected Sprite to NONE and it’ll fix the issue.
@CoolizardStudio you often don’t want to use animators in the UI generally for other reasons too: