Issues implementing UI event triggers via script

I have been trying to add Event triggers to my UI elements via script and get them to work. But the events just never fire or do anything, and I can’t find any answers as to what could be causing the issue. Here is the code used to add the event:


EventTrigger trigger = abilityIcon.AddComponent<EventTrigger>();
EventTrigger.Entry entry = new EventTrigger.Entry();
entry.eventID = EventTriggerType.PointerEnter;

entry.callback.AddListener((eventData) =>
{
    Debug.Log("Event!");
});

trigger.triggers.Add(entry);

And here is an image of the UI element in my editor after running the game:



I’ve tried deleting every other UI element except for the one with the event trigger so that I know nothing is blocking it. But the function never seems to fire under any event type.

If anybody has any ideas about what could be causing the issues I’d really appreciate it!


in my experience, listeners that are added via code are not visible in the inspector when the game is running.