Physics Layers
Physics layers provide a method for filtering collisions between colliders. They are also used by sensors to filter which colliders should be detected. Each layer must have a unique name, but a 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. This 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 layer.
Please visit our API documentation site for further details.
Sensors
It’s important to understand that assigning a layer to a sensor does not necessarily mean that the sensor should detect colliders that are assigned that particular layer. It 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 pairs of colliders 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 and configure the layer to not interact with itself.