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. Five are built in: Default (0), TransparentFX (1), Ignore Raycast (2), Water (4) and UI (5). Layers 3, 6 and 7 used to be reserved too, but current Unity versions let you name them, leaving 27 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?
Common causes: you edited the 2D matrix (Physics 2D settings) for a 3D game or the other way round; neither object has a Rigidbody, so no contact is ever generated; a script calls Physics.IgnoreLayerCollision at runtime and overrides the settings; or the objects are not on the layers you think. Check the layer on the GameObject that owns the collider, not just its parent.

Last updated: