Do triggers detect other triggers?

Working on a Boids flocking system and having two colliders for each of my boids; a box collider for physics collsions and a sphere collider marked as Trigger for detecting other boids. Will two sphere colliders marked as Triggers detected each other or will they only detect the box colliders?

Here’s code to help visualize:

void OnTriggerEnter (Collider other)
    {
        GameObject newNeighbor = other.GetComponent<SphereCollider> ().gameObject;
        if (newNeighbor.tag == "Enemy" && neighbors.Count < maxNeighborCount)
            neighbors.Add (newNeighbor);
    }

    void OnTriggerStay(Collider other)
    {
       
    }

    void OnTriggerExit(Collider other)
    {
        GameObject oldNeighbor = other.GetComponent<SphereCollider> ().gameObject;
        if (oldNeighbor.tag == "Enemy" && neighbors.Contains(oldNeighbor))
            neighbors.Remove (oldNeighbor);
    }

Yes.

Nice. Thanks.

Go to the bottom of this page and you’ll see what combinations with trigger:

My basic rule of thumb is that anything that needs to receive events (has scripts attached to the same GameObject that expect events), it should have a Rigidbody set to kinematic.

Huh. Was this always the case? I seem to remember triggers not effecting each other.

Anyway, something for me to keep in mind in the future. As triggers firing other triggers seems very counter intuitive to me.

That was so troubling for my project. But I found an answer to this.

A trigger will detect other triggers only if it has a Rigidbody attached to it. Removing the Rigidbody will make the trigger detect only colliders. This worked only for the triggers that are also children to the same parent

1 Like

As the grid in the link I supplied 5 years ago demonstrates.

It’s that 1 of the 2 interacting colliders must have a rigidbody. Which one is up to you… just 1 of them has to.

A collider with no RB is referred to as a “static rigidbody” and static colliders don’t interact with other static colliders. The main reason being a “static” body it is considered to be “static” or “unmoving”. How would 2 colliders that are supposed to not move ever change from a non-intersecting state to an intersecting state?

Now you might say because you can attach a static collider to something and then change its position.

And yes you can do that in practice.

But from the perspective of the engine that was NOT a simulation. It’s just not how the engine works. If you have colliders constantly changing position it should have a Rigidbody attached. That’s what signals to the engine that it should expect this collider to be dynamic/move.

This requirement is to keep performance up. Because otherwise it’d have to track every collider for movement, which would be wasting energy on colliders that wouldn’t otherwise move.

My issue was that there are several different triggers (static, nonstatic, with RB, and with not) around the scene and on the player. So my trigger would interact with some of them. I finally found the solution here. Using “isTrigger” in my code to exclude all triggers from getting detected.

void OnTriggerEnter(Collider col){
     if(!col.isTrigger){
         DoStuff();
     }
}
2 Likes

When you are looking for an answer and your old self has the solution :roll_eyes::roll_eyes::roll_eyes:

3 Likes