OnTriggerExit2D doesn't work when one of gameObject setActive false.
I have two triggers. One of them have this code( this code on game object "Item"):
void OnTriggerEnter2D(Collider2D other)
{
if (other.gameObject.name == "wallTop")
{
Item2TouchWallTop = true;
Item2TouchItemsTop = true;
}
}
When I move one of this game objects or only Item all works correctly, but when I setActive false on "wallTop" OnTriggerEnter and OnTriggerExit doesnt work. I dont understand why. Please help!
Which objects have a rigidbody? By the way this is what the docs say: "Trigger events will be sent to disabled $$anonymous$$onoBehaviours, to allow enabling Behaviours in response to collisions." I think this only means disabled scripts, not disabled gameobjects
"wallTop" have a rigidbody. I thought that the problem is that the "Item" is checked what came out of and because the "wallTop" is setActive fasle, "if" (if (other.gameObject.name == "wallTop") ) doesnt start. But doesnt start all method OnTriggerExit2D when I "wallTop" setActive false.
As @JedBeryll points out, you're describing expected behaviour - disabled gameobjects won't send collision messages.
If I understand correctly OnTriggerExit2D work well. $$anonymous$$aybe you have idea how to fix this issue?
The way to "fix" the issue is to only expect OnTriggerEnter2D to fire when there is a collision between two active gameobjects (with colliders and at least one with a rigidbody etc. etc.)
Your answer
Follow this Question
Related Questions
How do I differentiate between the triggers? 1 Answer
math.Lerp not correct? 1 Answer
C# OnTriggerEnter Issue 3 Answers
OnTriggerEnter For Parking 1 Answer
OnTriggerEnter/Exit Rapid Firing? 0 Answers