- Home /
OnTriggerExit is getting called even tho neither object moves
Hello All, I have an Static Trigger Collider that is a child of my camera which has a kinematic rigidbody. I use this trigger collider to activate gameplay objects when they enter it and deactivate them when they leave it. The gameplay objects that are being activated and deactivated have Static Non Trigger Colliders. Now this works most of the time, in that my gameplay objects are activated when they enter the activation collider and deactivate when they leave it. The problem is that sometimes when the gameplay objects are inside the activation collider and neither the gameplay object or activation collider is moving or changing in any perceivable way, I will get an OnTriggerExit() event on the gameplay object indicating that it had left the activation collider even tho the transform of neither object changed.
Why would this happen? What can I do to prevent this from happening.
Thanks,
I'm having the same problem. I'll add in some details, see if it helps.
Here's the code I'm using:
function OnTriggerExit(other: Collider){
if (other.tag == "mesa"){
print("OnTriggerExit");
manager.dragging = null;
manager.ponta = null;
}
}
(never$$anonymous$$d the portuguese).
The object with this script has RigidBody and it's Collider is a trigger. When it touches the other collider, it'll trigger an OnTriggerEnter function and then, after a few moments of staying still, will trigger the OnTrigger Exit. If I move the object (with the colliders still colliding), it'll trigger OnTriggerEnter again, and then OnTriggerExit after a moment.
No answer from me, unfortunately! I have almost the opposite problem. I put culling volumes throughout my level. These are simply box colliders set as triggers. Entering one enables it's chuck of the level, while exiting will disable the associated level chunk. $$anonymous$$y player uses a character controller but the culling volumes themselves have the script on them to detect the onTriggerEnter and Exit. Well, about 50% of the time, if I stand somewhere and let an enemy hit me (can't be moving the player for this to work) an onTriggerExit will get picked up by whatever culling volume I'm in and the level chunk will disappear for one frame as a onTriggerEnter is called right after.
check all the axis. $$anonymous$$ay be one of them is not same ...
You don't need the 'other.tag == "mesa"'. Basically you are calling the object tagged as 'mesa' without being inside the trigger, even if you are half way across the map from it.
Answer by jasonpvp · Dec 28, 2015 at 04:53 PM
@yardlevy I'm new to Unity (using v5) so don't quote me on this, but I experienced the same thing when I had two colliders on the same object - one that was for physics collisions and the other just a trigger. When I moved the physics collider to a child object the problem vanished. I think this tutorial mentioned something about it: https://unity3d.com/learn/tutorials/projects/stealth/single-doors?playlist=17168