Game Dev Cheat Sheet

Unity Physics Layers and Collision Matrix

Interactive Unity collision matrix editor with presets and C# code export.

Unity's Physics Layer Collision Matrix controls which layers can collide with which. Configuring it correctly reduces unnecessary physics checks and prevents unwanted collisions. This interactive editor lets you toggle collisions, apply game-genre presets, and export the configuration as C# code.

Edit
Project Settings
Physics
Layer Collision Matrix

Layer Names

Layers 0 to 5 are Unity built-in and cannot be renamed. Layers 6 to 9 are custom and editable.

Layer 0Default
Layer 1TransparentFX
Layer 2Ignore Raycast
Layer 3 
Layer 4Water
Layer 5UI
Layer 6
Layer 7
Layer 8
Layer 9

Presets

All layers collide with all layers.

Collision Matrix(55/55 pairs enabled)

Collides Ignores
DefaultTransparentFXIgnore RaycastWaterUIPlayerEnemyProjectileEnvironment
Default
TransparentFX
Ignore Raycast
Water
UI
Player
Enemy
Projectile
Environment

C# Code Output

// ============================================
// Physics Layer Collision Configuration
// ============================================
//
// Collision summary:
//   Default collides with: Default, TransparentFX, Ignore Raycast, , Water, UI, Player, Enemy, Projectile, Environment
//   TransparentFX collides with: Default, TransparentFX, Ignore Raycast, , Water, UI, Player, Enemy, Projectile, Environment
//   Ignore Raycast collides with: Default, TransparentFX, Ignore Raycast, , Water, UI, Player, Enemy, Projectile, Environment
//    collides with: Default, TransparentFX, Ignore Raycast, , Water, UI, Player, Enemy, Projectile, Environment
//   Water collides with: Default, TransparentFX, Ignore Raycast, , Water, UI, Player, Enemy, Projectile, Environment
//   UI collides with: Default, TransparentFX, Ignore Raycast, , Water, UI, Player, Enemy, Projectile, Environment
//   Player collides with: Default, TransparentFX, Ignore Raycast, , Water, UI, Player, Enemy, Projectile, Environment
//   Enemy collides with: Default, TransparentFX, Ignore Raycast, , Water, UI, Player, Enemy, Projectile, Environment
//   Projectile collides with: Default, TransparentFX, Ignore Raycast, , Water, UI, Player, Enemy, Projectile, Environment
//   Environment collides with: Default, TransparentFX, Ignore Raycast, , Water, UI, Player, Enemy, Projectile, Environment
//
// ============================================

void SetupLayerCollisions()
{
    // All layers collide with all layers (Unity default).
    // No Physics.IgnoreLayerCollision calls needed.
}

Frequently asked questions

How many physics layers can Unity support?
Unity supports 32 layers total. Layers 0-7 are reserved by Unity (Default, TransparentFX, Ignore Raycast, Water, UI, and a few unused). You have 24 layers free for your own use. Plan early; reorganising layers later is painful.
What is the difference between layers and tags?
Layers control physics interactions and rendering culling. Tags are simple string labels for runtime checks. Use a layer to stop two object types from colliding. Use a tag to identify a specific kind of object in code.
How do I make a raycast ignore certain layers?
Pass a LayerMask to Physics.Raycast. Build the mask with LayerMask.GetMask("Player", "Enemy") to include those layers, or invert it with the bitwise NOT operator (~) to exclude them. Cache the mask once rather than building it per frame.
Why is my collision matrix being ignored?
Two common causes: one of the objects has no Rigidbody (so it counts as static and ignores some matrix entries), or you are using a Trigger when you expected a Collider. Check both objects have correct components and that their layers are set in the Inspector, not just in code.

Last updated: