How to prevent object collision with its spawner

I have an bullet which can hit enemy as well as player. So if player spawns bullet it shoudnt collide with player but hit enemy and vice versa. Is there anyway to make this happen without use of layers.

Hiya,

Well, without layers, you can use Physics.IgnoreCollision(). Given two colliders, it will make the two ignore each other. If the player is made up of multiple colliders though, you’d have to call this for each one which wouldn’t be all that bad:

Collider[] playerColliders = player.GetComponents<Collider>();
playerColliders bulletCollider = bullet.GetComponent<Collider>();

// Make the bullet ignore all of the player's colliders
foreach (Collider c in playerColliders) {
    Physics.IgnoreCollision(bulletCollider, c, true);
}

Something like that at least.