I've been working with UI in my project as of late and I can't figure out what Unity's event system is supposed to return for currentSelectedGameObject.

if (EventSystem.current.currentSelectedGameObject != null)

With the code above I figured that it should return something when I'm moving the mouse across the various UI elements. Unity's documentation appears to be poor on this function stating:

The GameObject currently considered active by the EventSystem.

maybe I'm just being stupid but does anyone know what triggers currentSelectedGameObject?


The currentSelectedGameObject is not updated by simple mouse-over, as far as I'm aware.

Instead, it's more analogous to moving through an interface with tab. In the Unity UI system, you can move around between buttons with the keyboard. I think you'll find that behaves as expected.

If you want to know what UI object the mouse is over, I believe you'll need to implement that manually.

Quoting from: (4.6 UI) How to detect mouse over on button on answers.unity3d.com.

  • Add an event trigger component to your button game object.
  • Click on Add New button and select PointerEnter.
  • Now click on + button to add a new item to the list of event of type PointerEnter(BaseEventData).
  • Select the object containing your script.
  • Now select the function to be called from the list of functions.
  • \$\begingroup\$ Ahh that makes sense. why not mention that in the documentation though... \$\endgroup\$ – user3797758 Dec 30 '15 at 23:17
  • \$\begingroup\$ Agreed - it is an odd oversight in the docs, with broken links and all that lovely jazz. I think it's a consequence of the EventSystem existing before the 4.6 UI update, so there's misalignment between them. \$\endgroup\$ – Chris Mills-Price Dec 30 '15 at 23:20
  • \$\begingroup\$ I talked to one of the documentation staff at a Unity conference about this and it was noted down. So hopefully they will look at this soon. \$\endgroup\$ – user3797758 Aug 15 '17 at 15:25

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.