OnCollision2D stopped working

Hello everyone,

I have a weird issue with OnCollision2D.

I’ve setup my player with a 2D collider, I’ve also setup the ground he is walking on with a 2D collider.

The player also has a 2D rigidbody on it, the ground does not.

The player script (attached to the player) has 2 OnCollision2D methods, OnCollisionStay2D and OnCollisionExit2D.

The player also has an animator that animates its sprite.

At that point, everything is working fine, both OnCollision2D methods are being called.

Then, I added another animation to the character.

In that animation, I’m also animating the colliders (changing their shape and size).

As soon as I added this new animation, both of the OnCollision2D methods stopped working, even before I’m calling the new animation.

If I disable the Animator component on the player, then the methods are working again.

Any ideas?

I have run into strange issues with 2d colliders and found that they are very flaky unless they both have rigid bodies. I never figured out why, but if you put a rigid body on the ground, does it work? I’m not sure if that fixes your problem, as I’m sure you have a reason for not putting a rigid body on it, but at the very least it could give you some more information as to what’s happening.