Search code examples
c#unity-game-enginetriggerscollider

Unity : is it possible to configure the scene for trigger colliders to only work with one layer?


Unity already manages the collisions and triggers well but I would like to know if I can optimise triggers to only react to a layer ?

Currently if I have many different objects with colliders in a scene I need to do :

void OnTriggerEnter (Collider other) {
    if (other.gameObject.layer == myLayer) {
        // do stuff here
    }
}

But this means that the collisions where calculated with ALL of the colliders witch does not seem efficient.

If I want a trigger to react to the player and to the player only, is there a way to tell it to ignore all of the other layers to avoid unnecessary computing ?


Solution

  • Yes, using the Collision Matrix as described in the manual here.