OnTriggerEnter2D fires multiple times when Animator component is on

Hi all,

I have an issue with OnTriggerEnter2D firing multiple times when a target’s animator component is turned on. I’ve 25080-trigger2dproblem.zip (179 KB) to demonstrate the problem.

I created 2 entities, one called Car and one called Person, with the following settings:

The scene starts out with the Car to the left of the Person. The Car moves toward the person using the Car’s rigidbody2D’s velocity. If the Person’s Animator component is on, the OnTriggerEnter2D in the Car script will fire what looks to be every frame their colliders intersect. When I turn the Animator component off, it behaves expected and OnTriggerEnter2D only fires once. It doesn’t matter if anything is even physically moving - I created an empty state for the Person’s controller and set it as default and it still triggers multiple OnTriggerEnter2D’s.

I set up this scenario with regular 3D colliders and it behaves as I expected, so I’m leaning toward this being a bug with the new 2D tools, but I’d like to be sure.

I’ve already tried searching for OnTriggerEnter2D issues on Answers and on Google, but most of them either involve triggers not working, or assumed to be firing multiple times because of a symptom arising from bad code.

Any help appreciated, thanks very much!

I faced the same problem.I have solved the problem in your scene attached below.

[25090-25080-trigger2dproblem.zip|25090]

I believe this indeed is a Unity bug. bansalgirish8’s workaround only works in that specific use case, and even so, only once.

I’ve implemented a workaround where I maintain a list of colliders that have triggered OnTriggerEnter2D once before, and ignoring them for every subsequent trigger until they are removed by OnTriggerExit2D. Not sure it’s the way to go, but it’s the best workaround I’ve been able to come up with so far.

Seems like there are a lot of bugs with OnTriggerEnter2D. I have the same issue, where a transform.rotate causes OnTriggerEnter2D to fire on the same frame as the rotation, even though the trigger has not yet exited the collider. If your animation has a rotation of any sort, that would seem to reflect the same symptoms as my bug.

I’m pretty sure it’s a bug.