EventSystem.lastSelectedGameObject is always null on some objects

Hello, I recently updated to 4.6.1 from one of the betas, I can’t exactly remember which one (18-20?) and after the update, inside the callback of some button’s onClick event, EventSystem.lastSelectedGameObject is always null… Nothing was changed in the code or the scene form before I updated, it worked before just fine.

I receive the event in my callback ( all of the buttons’ callbacks are set dynamically ), but lastSelectedGameObject is always null.

Even when creating new buttons, with a simple Image component, i still get lastSelectedGameObject to be null. Events fire fine, but always with a null reference to lastSelectedGameObject or currentSelectedGameObject.

I then tried switching to EventTriggers, but the same thing happened. Callback called just fine, but
BaseEventData.selectedObject as well as EventSystem.lastSelectedGameObject are still null.

Does anyone know if there’s a gotcha popped up since the beta that I’m missing? Can’t seem to find any other way to refer to the object that was just clicked…

Thanks!

Can’t you just use Selection.gameObject?

Selection.gameObject is for the Editor. I’m talking about the runtime engine, with uGUI. :slight_smile:

I worked around it by messing with the source, ( made PointerInputModule.GetLastPointerEventData public ) but it would be nice to know why it won’t work.

@Harito I ran into the exact same problem as you did. Could you please explain what you did to fix it? Thanks.

I’m not sure if this was your issue, but mine was having more than one EventSystem component floating around in my scene.