Two child colliders pops both, how to separate onTriggerEnter?

Hello,

I have parent object that contains 2 childrens with box collider.

Here’s object tree:

-BuildingWrapper = empty

– BuildingS1 = collider, script

– RoadModeCheck = collider, script

Im using BuildingS1 collider to check if building can be placed and it work good, if collider triggers with other then there’s no space for building. I did second collider called RoadModeCheck to check if building has access to the road so it can spawn NPC (it’s an RTS game as You probably assumed). I couldn’t imagine any other simple way to check if road is next to building so im using second collider.

However the RoadModeCheck collider triggers OnTriggerEnter in BuildingS1 collider. I don’t know how this is possible because they are both childrens? Is there a way to separate collider messages so I can place buildings properly and check for road at same time?

Thanks for any answers.

Regards

Ok, i think it might work for you.

  1. Create script, named for example DummyScript and attach it to BuildingWrapper - it will help to get this object from children:

    using UnityEngine;
    public class DummyScript : MonoBehaviour{}

yeah, it’s just empty class.
2) In OnTriggerEnter handler use this:

void OnTriggerEnter(Collider other)
{
    if(this.GetComponentInParent<DummyScript>().gameObject == 
       other.GetComponentInParent<DummyScript>().gameObject)
       {
          return;
       }
    ... you code here

}

so in if statement we determine, if colliding objects have same parent