- Home /
OnCollisionExit2D - NotWorking?
Hello everyone, thanks for your help.
So, I want to basically call onCollisionExit and onCollisionEnter but for reason Exit isn't being called.
I've created 2 GameObjects with rigidbodies2d and boxCollider2D.
Once the object I can move collides with the obstacle I get on my dbg:
"Touching"
But when I move away from that obstacle, onCollisionExit isn't being called.
Here's the code:
void OnCollisionEnter2D(Collision2D coll) {
Debug.Log ("Touched");
}
void OnCollisionExit2D(Collision2D coll) {
Debug.Log ("Stopped Touching");
}
What am I missing? OnCollisionEnter works, but exit isn't....
If it helps, the sprites don't overlap because of rigid body.
Here's some specs on boths rigidBody. Mass:1 LinearDrag:0 AngularDrag:0 GravityScale:0 FixedAngle=true; IsKinematic=false; interpolate=none; sleepingMode=startawake; collisionMode=discrete;
Only the object moving has rigidbody.
try these change one of the coll to a different name and does the debug warning of Touched continue even after exiting the collision if these don't help, it probably a bug somewhere in unity or your project
Touched doesn't continue after exiting collision.
I grabbed the function from the unity scripting.
Try using triggers, I find they work a bit better for on exit functions.
Your answer
![](https://koobas.hobune.stream/wayback/20220613151631im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
CharacterController and Normal rigidbody Box Collider Collision issues 0 Answers
onCollisionEnter reporting wrong collider? 0 Answers
prevent a player object from rotating on a moving platform? 1 Answer
onCollisionEnter doesn't work without RIgidbody? 1 Answer
RigidBody's Bug???How to solve it??? 0 Answers