- Home /
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?
Could be that you modified the z position of the sprite somehow, any screenshots you could provide?
I've checked, I'm not modifying the position anywhere in all of my animations.
Is there anything specific you want to see? I think I explained it pretty well.
Answer by Jonesy19 · Apr 23, 2014 at 06:07 PM
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.
Adding a rigidbody does not help.
And like I said, it was working perfectly one moment and then stopped working....
Your answer
Follow this Question
Related Questions
Collisions don't work with Animate Physics turned on 0 Answers
How to trigger the same animator state in unity5 with script? 2 Answers
Blender FBX Import to Unity messes up animations 1 Answer
Animator throws null reference exception for no reason 1 Answer
Delay between Animator animations without transitions 0 Answers