Multiple Colliders Trigger problem

hi community,

i’m completely stuck with colliders as triggers.

i have made a script that adds a box collider to an empty gameobject and adds this as a child to a gameobject.
this box collider scans nearby enemies.

so at the moment i have 2 such scripts on 1 gameobject.
that means 2 colliders in 2 empty gameobject in 1 gameobject (unit).
each unit has a rigidbody attached.

  1. unit(main gameobject)
  2. empty gameobject
    1. box collider (5/5/5)
  3. empty gameobject
    1. box collider (3/3/3)

the problem is when the greater box collider is triggered it automatically triggers the smaller box collider.
another problem is that the OnEnter and OnExit - Trigger functions always toggle (so the same gameobject (nearby enemy) enteres and exits all the time.

i hope it is clear enough.
thanks in advance.

i have just tried to the following:

add the “sensors” to each child object…now it works only if i add a rigidbody to each child object…but i think this is not the way it should work cause the rigidbodies fall through the actual sensors…

okay now it works fine!
you were totally right!
the solution to my problem was:
attach the script which attaches the sensor (collider) to each of the child gameobjects then check in a parent OnTriggerEnter() function

thank you so much…you brought me on the right way :wink:

I have run into this same problem and am posting with hopes that this will help somebody understand the problem and come up with a better work around.

from the Unity Docs: Collider.OnTriggerEnter(Collider)

This message is sent to the trigger
collider and the rigidbody (if
any) that the trigger collider belongs
to, and to the rigidbody (or the
collider if there is no rigidbody)
that touches the trigger. Note that
trigger events are only sent if one of
the colliders also has a rigidbody

the problem can be caused if (similar to the screenshots above) you have a rigidbody on a parent object, a trigger collider on the parent, a script on the parent that uses the trigger events, and a child object that has a trigger collider.

According to the docs the rigidbody is notified of the trigger collision, even if it is in the parent and has nothing to do with the specific trigger on the child. In my situation the child and the parent’s OnTriggerEnter() were both called when the player touched the sensor. The sensor area was for player detection. The Trigger on the parent was for detecting touching the player and dealing damage.

The work around which is mentioned above is to put a rigidbody on the sensor area child object. This seems to force the sensor area to use up the collision event and avoids relaying it to the parent’s rigidbody. I don’t like this solution at all because it relies on an non needed component. Hopefully somebody knows of a better way.