- Home /
OnTriggerExit called even if shouldn't
Hey there, I have 2 Objects, both have SphereCollider (isTrigger), Rigidbodies (isKinematic, ContinuousSpecuative, AllConstaraints checked). But very often OnTriggerExit called even when both objects are touching each other and don't move.
private void OnTriggerExit(Collider other){
if (other.CompareTag("OtherObject")){
//called even when both objects are touching each other and don't move.
}
}
I should have asked this first. What is going on in your scene? Is it a dead scene where nothing moves? Or is there motion besides the 2 spheres?
Answer by EugeneJefferson · Apr 11, 2021 at 11:25 PM
Maybe it's a bug, maybe I misunderstood something. To fix this you need to disable all child colliders(it's enough for my solution). For some reason, OnTriggerExit works with child colliders even if tag doesn't fit. Example: Object with tag "Object1" has 5 child objects with tags "Object2". If this Object moves through another one that tracks OnTriggerExit CompareTag("Object1"), OnTriggerExit will be called 6 times
Is this a brand new fresh project with only created objects or are there imported objects? Also have you updated the project version? I still cannot reproduce this so it doesn't seem to be an actual bug. Only the parent is activating the OnTriggerExit()
method and only once as would be expected.
Fresh project with created objects, project version is updated. I will try to provide you all the info I have to reproduce this bug
MacOS Big Sur 11.2.2, Unity 2021.1.2f1
Data: Object1 and Object2 both have: Rigidbody(Use gravity=false,isKinematic=true, Continuous Speculative, All Constraints), SphereCollider(IsTrigger=true).
Object1 tag is "Enemy", Object2 tag is "Player"
Object1 has script with OnTriggerExit CompareTag("Player"), Object2 has child objects with tag "ChildObjects"
When I move any of this objects through each other OnTriggerExit is called 1+childCount of Object2 times