- Home /
OnTriggerStay won't stop firing...!
Set up a Convex Mesh Collider Trigger. Have a script attached with OnTriggerStay.
Move mesh over a capsule collider: OnTriggerStay fires. Fine, that's cool. Move mesh away from capsule collider... OnTriggerStay carries on firing, until the capsule collider moves a certain amount. Not so cool. Why? How do I stop this from happening? Attaching a primitive collider trigger and everything works as intended.
It appears that if the capsule collider intersects with the surface of the trigger, then everything works as intended. If it goes completely inside, then the onTriggerStay gets caught firing.
One way to get around this is to keep manually updating the mesh of the trigger every frame. But eff me, that's a bit costly.
In anticipation of possible answers; can't do a raycast because there's going to be multiple objects on that physics layer, potentially overlapping. Can't use compound primitives either, necessary shape of trigger won't allow it.
$$anonymous$$aybe you should show us the code you use. Do you call OnTriggerStay yourself somewhere ?
OnTriggerStay will keep firing until both objects have 0 points of collision. I don't really understand what's the matter.
@$$anonymous$$iraSensei: S'not a code problem - functionality works completely fine with primitives. What happens is, on a Convex $$anonymous$$esh Collider (set to trigger...), OnTriggerStay fires if the surface of the $$anonymous$$esh Collider intersects with the capsule collider. $$anonymous$$ove it away again & OnTriggerStay stops firing as it should. HOWEVER, If the $$anonymous$$esh Collider is moved so that the Capsule Collider is completely inside of it, OnTriggerStay fires. $$anonymous$$ove the mesh collider away from the Capsule collider, so that neither are touching [& mesh collider isn't touching anything at all], OnTriggerStay carries on firing. OnTriggerStay only stops firing if the capsule collider is moved more than about 0.5 units. Or if the $$anonymous$$esh Collider is moved waaaay far away.
OnTriggerExit is a doable as a work around, but I'd rather keep things clean.
@oysterCA$$anonymous$$E: What version of unity are you using? I had the same problem myself in 4.3.4f1, but after trying 4.3.3 again the issue disappeared, after saving the scene in 4.3.3 it works in 4.3.4 until saving the scene again.
Edit: Sorry, tried it again with a clean project, and was still a problem in 4.3.3