- Home /
Why do I get OnTriggerExit upon collision when a rigidbody is kinematic? (example)
Hi!
I have organized my game in scenes that deactivate when the player leave them (static trigger colliders), and for this I use OnTriggerExit(). Sadly, I also need to occasionally set the player (which is a Rigidbody with a BoxCollider) to kinematic in order to do an animated ledgegrab. During the time that the player is kinematic, the scene occasionally receive an OnTriggerExit() call if something collides with the player. I̶t̶ ̶d̶o̶e̶s̶n̶'̶t̶ ̶h̶a̶p̶p̶e̶n̶ ̶e̶v̶e̶r̶y̶ ̶t̶i̶m̶e̶,̶ ̶b̶u̶t̶ ̶w̶i̶t̶h̶ ̶s̶o̶m̶e̶ ̶k̶i̶n̶d̶ ̶o̶f̶ ̶p̶r̶o̶b̶a̶b̶i̶l̶i̶t̶y̶.
Edit:
I created a minimalistic example.unitypackage. In the example the game will pause when the boxes collide, which is caused by my problem: the OnTriggerExit() being called (the example is deterministic).
I doesn't seem like anybody knows the reason, but maybe someone can test to see if it's still an issue in 3.5?
Did you ever resolve this issue? I think I'm seeing the same problem in 3.5.3: an enemy with a kinematic rigidbody and multiple colliders gets hit by a bullet, which sometimes calls OnTriggerExit even though the collider is clearly inside the trigger. In my case, I see the problem in iOS, but not in the editor.
I haven't checked since 3.5.0, but I've made a lot of workarounds. $$anonymous$$y guess is that the bug is still there. When I found it I had to experiment a bit before I found some positions that would provoke the bug, but it was not very hard to find.
Just texted in 4.x and this bug is still here. It was reported.
Answer by Statement · Dec 13, 2011 at 12:54 PM
I ran it, and it's mildly disturbing to say the least... If it is of any help, I changed the Collision Detection of the falling cube to Continous. After I did this, OnTriggerExit no longer fire on collision. Try if it would help your project. Why it would register as outside the trigger in the first place, I have no clue.
I agree that it's a bit disturbing. I'm not sure if the continuous mode worked is by chance or not. $$anonymous$$oving stuff around arbitrarily changes the result. For example changing the material fixes the example, but I hardly believe that it's a reliable fix. I'm going to test that tomorrow.
Using Continuous does not solve the problem, but it makes it less likely. This is a serious problem for us, and I think we have to abandon this way of using triggers.
Answer by steinbitglis · Sep 05, 2013 at 08:51 AM
I got this answer from Anthony (Unity QA):
We see that this bug is no longer reproducible with PhysX 3.3 we are working on now.
We are planning to switch to PhysX 3.3 in the future and then this bug would be gone.
Edit:
The bug is still there in 4.3
Answer by seedoubleyou · Dec 13, 2011 at 01:03 AM
Hard to tell from just your description, but obviously something is exiting your object's collider. You could try allowing the OnTriggerExit code to react only if an object with specific tags exit the collider.
For example:
function OnTriggerExit(col : Collider) {
if(col.gameObject.tag == "Enemy"){
//do something
}
}
It's not obvious, because I can't find anything exiting the collider. Take a look at my recent example package.