# contactMask

> Calculates the effective LayerMask that the Collider2D will use when determining if it can contact another Collider2D.

## Definition

* **Type:** Property
* **Namespace:** [UnityEngine](/engine/6000.3/script-reference/unityengine.md)
* **Assembly:** UnityEngine.Physics2DModule

```csharp
public LayerMask contactMask { get; }
```

### Remarks

The returned mask is calculated using a combination of the layer collision matrix and both the [Rigidbody2D](/engine/6000.3/script-reference/unityengine/rigidbody2d.md) and [Collider2D](/engine/6000.3/script-reference/unityengine/collider2d.md) layer overrides.; more detail is provided in the code example below:

Additional Resources: [Collider2D.CanContact](/engine/6000.3/script-reference/unityengine/collider2d/cancontact.md).

### Examples

```csharp
using UnityEngine;

public class Example : MonoBehaviour
{
    void Start()
    {
         var myCollider = GetComponent<Collider2D>();

         Debug.Log(myCollider.contactMask);
         Debug.Log(CalculateContactMask(myCollider));
    }

    LayerMask CalculateContactMask(Collider2D collider)
    {
        Rigidbody2D body = collider.attachedRigidbody;

        LayerMask layerCollisionMask = Physics2D.GetLayerCollisionMask(collider.gameObject.layer);
        LayerMask includeMask = collider.includeLayers | (body ? body.includeLayers : new LayerMask());
        LayerMask excludeMask = collider.excludeLayers | (body ? body.excludeLayers : new LayerMask());

        return (layerCollisionMask | includeMask) & ~excludeMask;
    }
}
```
