Search Unity

UnityEvent triggers method on wrong component when 2 of same type are assigned (2018.2.2f1)

Discussion in 'Scripting' started by Kylotan, May 21, 2019.

  1. Kylotan

    Kylotan

    Joined:
    Feb 17, 2011
    Posts:
    212
    Here's the situation:
    • One gameobject with:
      • a component containing a UnityEvent
      • a custom component, call it CustomBehaviourA
      • a 2nd custom component, call it CustomBehaviourB
    • The initial UnityEvent has 2 entries assigned, e.g.:
      • CustomBehaviourA.DoSomething()
      • CustomBehaviourB.DoSomething()
    When I call Invoke on the UnityEvent, it actually executes CustomBehaviourA.DoSomething() twice and does not execute CustomBehaviourB.DoSomething() at all.

    This looks a lot like this problem on Unity Answers.

    Is this a known bug? Has it been fixed since 2018.2.2f1?
     
  2. Kylotan

    Kylotan

    Joined:
    Feb 17, 2011
    Posts:
    212
    Bump! Would be nice to get a second opinion.
     
  3. palex-nx

    palex-nx

    Joined:
    Jul 23, 2018
    Posts:
    1,748
    There's no way to distinguish between two components of same type in Unity. I had same problem whith networking when added second gun script to player object trying to implement 2 hands shooting. I've just added GunID field to message and forgot bout that.