- Home /
PointerEventData.selectObject always null
Goodday fella's,
I've got a UI Text component with an Event Trigger attached to it, what I want to do is to catch either the value or name of the UI Text component. So I've got it working as far as that I'm getting PointerEventData in the function I'm calling with the Event Trigger, I've done it like this.
public void ClickedOnText(BaseEventData baseEventData)
{
PointerEventData pointerEventData = baseEventData as PointerEventData;
print(pointerEventData.selectedObject);
}
The problem however is that pointerEventData.selectedObject always returns null/empty. Somehow it does not register the Text gameobject... Other data like pointerEventData.button is available, so it's not completely empty. Just the clicked Object is nowhere to be found.
How can I fix this? How can I get the clicked gameobject's name/value?
Answer by unity_HnOPr0t65WKeug · Dec 18, 2020 at 11:28 AM
You can use eventData.pointerDrag, pointerEnter, pointerPress...
Answer by Cursedth · Oct 28, 2017 at 01:29 AM
You have to set it to set:
eventData.selectedObject = yourclickedobject
But the problem is that I want to figure out what the clicked object is, that is what I want to know. I might be mistaking but with your answer I must already know what I've clicked, and that's just the problem, I don't know that :)