Search Unity

OnTrigger callbacks called for ignored collisions

Discussion in 'Physics' started by austinborden, Aug 30, 2019.

  1. austinborden

    austinborden

    Joined:
    Aug 5, 2016
    Posts:
    7
    I'm running into an issue where the OnTriggerEnter2D/Stay2D callbacks are getting called even though collisions are ignored between the two colliders. In my script's
    OnTriggerStay2D(Collider2D other)
    method I checked
    Physics2D.GetIgnoreCollision(GetComponent<Collider2D>(), other)
    and it returns true. Can anyone think of a reason why the method would be triggered even if the engine knows the collision is supposed to be ignored?

    Also, this seems to only happen some of the time so it's getting to be very difficult to debug. I'm ignoring a few dozen collisions at the same time and these callbacks only happen for some of them.
     
  2. austinborden

    austinborden

    Joined:
    Aug 5, 2016
    Posts:
    7
    I just figured this out. It turns out I had a child GameObject with a collider on some of the ignored GameObjects. Since the children colliders weren't ignored, the OnTriggerStay message was being propagated up to the parent that was supposed to be ignored.