Astra Child

Not Setting Current Selected on Mouseover

Estimated reading: 2 minutes 0 views

Problem

On mouseover on a selectable component (button, toggle, tab, etc…) the EventSystem.current.currentSelectedGameobject is not set, but when using a keyboard (WASD, arrows), a controller or a gamepad then the component is always selected.

Solution

A selectable has 5 possible states:
1. Normal – not affected by anything and IS interactable
2. Highlighted – a pointer is hovering over it (Pointer Enter was triggered)
3. Pressed – a pointer is down on it (Pointer Down was triggered) OR it was triggered
4. Selected – the selectable is the currentSelectedGameObject in the EventSystem (there can be only one)
5. Disabled – the selectable IS NOT interactable

This is not a bug, but the correct behavior.

When a mouse over a selectable happens, the Highlighted state is triggered and NOT the Selectable state. After you click with the mouse (or pointer), the selectable goes to the Pressed state and the it becomes Selected (in the EventSystem). 

When using a keyboard or a controller or a gamepad, the Highlighted state is not triggered as the selectable goes directly in the Selected state via Unity’s Navigation system, when ‘jumping’ from selectable to another.

So, what you’ve seen happen, is not a bug, but the correct and expected behavior when using these different ways of interacting with a UI (in this case Unity’s UI).

Share this Doc
CONTENTS
Scroll to Top