Search Unity

Unity UI adding EventTrigger staying after runtime?

Discussion in 'UGUI & TextMesh Pro' started by coshea, Jul 31, 2018.

  1. coshea

    coshea

    Joined:
    Dec 20, 2012
    Posts:
    319
    So I am using this code to add eventTrigger listeners
    https://docs.unity3d.com/ScriptReference/EventSystems.EventTrigger.html

    Code (csharp):
    1.  
    2. trigger = GetComponent<EventTrigger>();
    3. EventTrigger.Entry entry = new EventTrigger.Entry();
    4. entry.eventID = EventTriggerType.PointerDown;
    5. entry.callback.AddListener((data) => { OnPointerDownDelegate((PointerEventData)data); });
    6. trigger.triggers.Add(entry);
    7.  
    I have an empty eventTrigger component added to my button

    eventrigger1.png

    When I run in the editor, i can see the new event ...

    eventrigger2.png

    but when you press STOP in the editor, the event trigger added remains. When I run it again, it adds another one...

    eventtrigger3.png

    Only just realised when looking at the button and finding 100 pointerDown event triggers in the list

    Why are they staying if they are added in runtime?

    Do they have to be removed when the game stops playing?

    Thanks
     
  2. coshea

    coshea

    Joined:
    Dec 20, 2012
    Posts:
    319