Physics Layers
Physics layers provide a method for filtering collisions between colliders. They are also used by sensors, to filter the colliders that can be detected by the sensor. Each layer must have a unique name, although the same layer can be assigned to many different colliders. You can specify all the layers that should interact with any given layer. If a layer isn’t set for a collider/sensor, then it is assigned the default layer, which interacts with all layers.
You can create a new physics layer, or edit an existing physics layer, by clicking the button to the side of the “Layer” property on a physics component. Doing this replaces the inspector with a new pane, which allows you to specify a row of the physics collision layer matrix. The matrix defines whether two layers can interact through collisions or not. Note that the default physics layer is not editable and all layers implicitly interact with the default physics layer.
Please see the API documentation page for more information about physics layers.
Sensors
It is important to understand that assigning a layer to a sensor does not necessarily mean that the sensor should detect colliders that are assigned that layer. You can configure a layer to not interact with colliders that have the same layer.
Assigning a layer to a sensor specifies that the sensor has that particular layer. The colliders that are detected are any colliders with layers that are set to interact with the sensor’s layer. For example, it is common to create a “Sensors” layer, which can then be configured to interact with any other layers.
Performance
Layers can be used to improve performance by reducing the number of collider pairs that need to be tested during collision detection. For example, if you don’t need your robot to be able to collide with itself, you can create a “Robot” layer, assign that layer to every link of your robot, then configure the layer to not interact with itself.