BaseEventData.selectedObject nil for Images and Text Labels

When I add an Event Trigger type (Pointer Enter, Pointer Exit, etc) for images or text labels using a callback such as:

public void BeginHover(BaseEventData data)
{
    Debug.Log(data.selectedObject);
}

The selectedObject property is always nil, and not the UI element. With buttons, the selectedObject is the button.

Is there anyway that I can use one callback with multiple UI elements? I’m looking to retrieve the image and label objects that the pointer is hovering over.

Thanks!

So if have a scene with a number UI images, there’s not a way that I can use a Event Trigger to determine which images are being hovered over without setting each image’s event trigger to its own callback?

On the UI object → Add component → UI → Selectable and the selectedObject property will no longer be nill.

4 Likes