VulCode

Unity LayerMask

Tick layers and get the bitmask for Physics.Raycast plus a line of C#.

Category
SCP:SL, Steam and Unity
Price
free

The tool starts in your browser.

Everything is calculated in your browser. Nothing you type is sent to our server.

How to use it in three steps

The tool as a schematic with this page's example. Each step's number stands where you take it: in the fields, at the result or outside the tool.

Unity LayerMask
What you enter
Layers 0 (Default), 8 (Player) and 9 (Enemy)
  1. Tick the layers the raycast should see.

What you get
LayerMask mask = LayerMask.GetMask("Default", "Player", "Enemy"); 769 = 0x00000301
  1. Read the mask number.

  2. Copy the C# line with the LayerMask.

Six sets of layers and their mask

Physics.Raycast takes a mask, not a layer number: layer n is 1 << n. Layer 31 is the sign bit, which is why an int with it comes out negative, and a full mask is -1.

LayersExpected maskWhat the tool returnsResult
Layers0, 8, 9the example from the tool's description
Expected mask(1 << 0) | (1 << 8) | (1 << 9) = 769
What the tool returns769 (0x00000301), GetMask with 3 names
As expected
Layers2Ignore Raycast only
Expected mask(1 << 2) = 4
What the tool returns4 (0x00000004), GetMask with 1 name
As expected
Layersall but 2everything but Ignore Raycast, the Invert button
Expected mask~(1 << 2) = -5
What the tool returns-5 (0xFFFFFFFB), GetMask with 31 names
As expected
Layers31the last layer is the sign bit
Expected mask(1 << 31) = -2147483648
What the tool returns-2147483648 (0x80000000), GetMask with 1 name
As expected
Layers0-31all 32 layers
Expected mask~0 = -1
What the tool returns-1 (0xFFFFFFFF), GetMask with 32 names
As expected
Layers-nothing ticked
Expected mask0 = 0
What the tool returns0 (0x00000000)
As expected

6 of 6 cases as expected

Questions