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)

Unity - Manual: OnTrigger events
Unity - Scripting API: Collider.OnTriggerEnter(Collider)

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.

I have never posted before, but I seemed to have a very similar problem to Lattman that I was frustrated with for hours. I had a trigger box collider on the root game object of the enemy and a capsule collider on the root game object of the player. Additionally, there was a trigger box collider on the weapon the player was holding that was enabled and disabled depending on when the player was attacking.

However, the “OnTriggerEnter” method that was in a script placed on the root of the player which read the collision between the weapon trigger box collider and the enemy trigger box collider would register a collision even when I was not attacking (when the player and enemy made contact with each other).

After spending most of the night trying to fix the problem, I was able to find the following documentation that helped steer me in the right direction to get it working properly:

Specifically, the part about NavMesh Agents and Physics interactions helped me. I had to reconfigure a few things to make it where my player moved with a NavMesh Agent instead, but once I did that, the information provided in the documentation solved my problem.

I removed the capsule collider from the player root game object, added a Rigidbody to it and also a Rigidbody to the root enemy game object. Then, I checked the box on the Rigidbody components that says “IsKinematic” and everything worked as intended after that.

I hope I am using this forum correctly and that this information helps someone else too.