Adding EventTrigger.Entry to EventTrigger component via script doesn't update component's editor UI
When adding an entry to EventTrigger via script, the delegate is not displayed in the Event Trigger's editor UI as one would expect. If you change to "Debug" mode in the inspector window, you can see that there is a second delegates array that does contain the functioning entry, however. Is there a way to approach this that will display the UI components correctly or is this just a bug / intended?
void Start()
{
EventTrigger trigger = AddComponent<EventTrigger>();
EventTrigger.Entry entry = new EventTrigger.Entry();
entry.eventID = EventTriggerType.PointerDown;
entry.callback.AddListener((data) => { OnPointerDownDelegate((PointerEventData)data); });
trigger.triggers.Add(entry);
}
public void OnPointerDownDelegate(PointerEventData data)
{
Debug.Log("OnPointerDownDelegate called.");
}
Debug:
Normal:
Hello @mikeburnsshadow, I have exactly the same problem. Did you manage to solved it?
(I'm using the 2017.1.p04)
$$anonymous$$any thanks,
Ah ok, thanks for your quick reply. So everything's working (callback, trigger,...) but the list of callback in the editor still remain empty after running.
Interesting.. when creating the trigger events via a custom inspector button click, the triggers don't work when going into Play mode. However, creating them in Start() as you did does work. It appears that a trigger can only be added via script during Play mode for it to work. (although, yeah it doesn't show up in the inspector...)
Your answer
Follow this Question
Related Questions
UnityEvent with all derived types in listeners serialized in Inspector 0 Answers
Twitch Chat Emotes & Alerts to trigger events C# 0 Answers
Trigger events with bullets 0 Answers
How to stop object from going to center of mouse when dragging starts 0 Answers
Way to assign event fields in created at runtime scriptable object (ScriptableObject Architecture) 0 Answers