UNITY

Layer Mask Calculator

Convert Unity layer selections to integer, hex, binary, and ready-to-paste C#.

BIT MASKS

Select Unity layers

Browser-only
Integer
Hex
Binary (32-bit)
C# (Unity)
Each Unity layer is a bit. The mask value is the sum of 2^layer for every checked layer. Use the C# expression directly in Physics.Raycast or LayerMask.GetMask.

Layer mask guide

Unity layer masks are one of the most-searched game dev gotchas: you know you need to filter a raycast to "ground and walls only", but the inspector shows a mask while your code needs a number. This calculator converts between the two instantly — tick the layers you want, and copy the integer, hex, binary, or ready-made C# expression.

How layer masks work

Unity has 32 layers, each represented by one bit in a 32-bit integer. A mask is just that integer with bits set for the layers you care about: layer 3 is bit 3, so its mask value is 2³ = 8. Multiple layers are summed — layers 3 and 5 give 8 + 32 = 40.

The inspector shows you friendly checkboxes, but the underlying value is the plain integer you pass to Physics.Raycast, Physics.OverlapSphere, or LayerMask.GetMask in code.

Why devs get this wrong

The classic bug is using the layer index instead of the bit value. Passing 5 when you mean layers 0 and 2 is a silent, hard-to-trace collision bug. The second classic is hard-coding masks — a magic number like 256 that breaks the moment someone reorders the layers. Always build masks from layer names or constants.

Tip: Use the C# output from this tool — `1 << 8 | 1 << 9` is self-documenting and survives layer reordering far better than a magic integer.

Frequently asked questions

What is a layer mask value?

A 32-bit integer where each bit represents one Unity layer. Bits set to 1 include that layer in the mask; bits set to 0 exclude it.

How do I convert a layer index to a mask value?

Compute 2^index (or 1 << index in code). Layer 0 is 1, layer 1 is 2, layer 5 is 32, and so on.

Why does my raycast ignore objects I selected?

You are probably passing a layer index instead of a bit mask. Use this tool to get the correct integer, or use LayerMask.GetMask("Ground", "Wall") in code.

Privacy note: layer mask calculations and copying happen in your browser. Nothing is uploaded.