- Home /
OnTriggerEnter2D being called by GameObject without the trigger
If I understand correctly, according to the Unity API, OnTriggerEnter2D() is run whenever another object enters the trigger on the current object (e.g if A's script has OnTriggerEnter2D() and it has a trigger, it will run when B enters it)
However, I've noticed that when B has OnTriggerEnter2D() (also, B doesn't even have a trigger collider), when it collides with A (which DOES have the trigger) the method still runs.
This isn't necessarily a problem I just was wondering if anyone knew why this happened?
Answer by TonyLi · Jun 28, 2017 at 01:03 AM
That's the way it's designed. Whenever there's a collision with a trigger, both objects receive OnTriggerEnter() / OnTriggerEnter2D() messages, not just the object with the trigger.
Oh okay, then that makes a lot of sense. I thought it was only supposed to run on the object with the trigger so I thought I was doing something wrong.
Thanks!
Your answer
Follow this Question
Related Questions
How to destroy a gameobject's clone when colliding with the ground? 1 Answer
Platform Collider Not Working When Enemy Collides With It 1 Answer
Draw line within bounds of circular collider 0 Answers
Can more than one colliders be used for different purposes..???? 1 Answer
Why the npc character walking strange when using a Rigidbody and Is Kinematic on enabled ? 1 Answer