# ContactFilter2D

> A set of parameters for filtering contact results. Define the angle by referring to their position in world space, where 0 degrees is parallel to the positive x-axis, 90 degrees is parallel to the positive y-axis, 180 degrees is parallel to the negative x-axis, and 270 degrees is parallel to the negative y-axis.

## Definition

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

```csharp
public struct ContactFilter2D
```

## Remarks

Use a contact filter to precisely control which contact results get returned. This removes the need to filter the results later, is faster, and more convenient.

If you are using a function that requires a [ContactFilter2D](/engine/6000.0/script-reference/unityengine/contactfilter2d.md), but you don't want to perform any filtering, then use [ContactFilter2D.NoFilter](/engine/6000.0/script-reference/unityengine/contactfilter2d/nofilter.md).

For more information on using [ContactFilter2D](/engine/6000.0/script-reference/unityengine/contactfilter2d.md) with casting, see: [Physics2D.CircleCast](/engine/6000.0/script-reference/unityengine/physics2d/circlecast.md), [Physics2D.BoxCast](/engine/6000.0/script-reference/unityengine/physics2d/boxcast.md), [Physics2D.CapsuleCast](/engine/6000.0/script-reference/unityengine/physics2d/capsulecast.md), [Physics2D.Linecast](/engine/6000.0/script-reference/unityengine/physics2d/linecast.md), [Physics2D.Raycast](/engine/6000.0/script-reference/unityengine/physics2d/raycast.md), [Collider2D.Raycast](/engine/6000.0/script-reference/unityengine/collider2d/raycast.md), [Collider2D.Cast](/engine/6000.0/script-reference/unityengine/collider2d/cast.md) and [Rigidbody2D.Cast](/engine/6000.0/script-reference/unityengine/rigidbody2d/cast.md).

For more information on using [ContactFilter2D](/engine/6000.0/script-reference/unityengine/contactfilter2d.md) with overlapping areas, see: [Physics2D.OverlapPoint](/engine/6000.0/script-reference/unityengine/physics2d/overlappoint.md), [Physics2D.OverlapCircle](/engine/6000.0/script-reference/unityengine/physics2d/overlapcircle.md), [Physics2D.OverlapBox](/engine/6000.0/script-reference/unityengine/physics2d/overlapbox.md), [Physics2D.OverlapArea](/engine/6000.0/script-reference/unityengine/physics2d/overlaparea.md), [Physics2D.OverlapCapsule](/engine/6000.0/script-reference/unityengine/physics2d/overlapcapsule.md), [Physics2D.OverlapCollider](/engine/6000.0/script-reference/unityengine/physics2d/overlapcollider.md), OverlapCollider and OverlapCollider.

For more information on using [ContactFilter2D](/engine/6000.0/script-reference/unityengine/contactfilter2d.md) with contacts, see: [Physics2D.GetContacts](/engine/6000.0/script-reference/unityengine/physics2d/getcontacts.md),  [Collider2D.GetContacts](/engine/6000.0/script-reference/unityengine/collider2d/getcontacts.md), [Rigidbody2D.GetContacts](/engine/6000.0/script-reference/unityengine/rigidbody2d/getcontacts.md),  [Physics2D.IsTouching](/engine/6000.0/script-reference/unityengine/physics2d/istouching.md), [Rigidbody2D.IsTouching](/engine/6000.0/script-reference/unityengine/rigidbody2d/istouching.md) and [Collider2D.IsTouching](/engine/6000.0/script-reference/unityengine/collider2d/istouching.md).

## Fields

| Value                                                                                                         | Description                                                                                                                                                                                                                                                                                                              |
| ------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| [layerMask](/engine/6000.0/script-reference/unityengine/contactfilter2d/layermask.md)                         | Sets the contact filter to filter the results that only include [Collider2D](/engine/6000.0/script-reference/unityengine/collider2d.md) on the layers defined by the layer mask.                                                                                                                                         |
| [maxDepth](/engine/6000.0/script-reference/unityengine/contactfilter2d/maxdepth.md)                           | Sets the contact filter to filter the results to only include [Collider2D](/engine/6000.0/script-reference/unityengine/collider2d.md) with a Z coordinate (depth) less than this value.                                                                                                                                  |
| [maxNormalAngle](/engine/6000.0/script-reference/unityengine/contactfilter2d/maxnormalangle.md)               | Sets the contact filter to filter the results to only include contacts with collision normal angles that are less than this angle.                                                                                                                                                                                       |
| [minDepth](/engine/6000.0/script-reference/unityengine/contactfilter2d/mindepth.md)                           | Sets the contact filter to filter the results to only include [Collider2D](/engine/6000.0/script-reference/unityengine/collider2d.md) with a Z coordinate (depth) greater than this value.                                                                                                                               |
| [minNormalAngle](/engine/6000.0/script-reference/unityengine/contactfilter2d/minnormalangle.md)               | Sets the contact filter to filter the results to only include contacts with collision normal angles that are greater than this angle.                                                                                                                                                                                    |
| [useDepth](/engine/6000.0/script-reference/unityengine/contactfilter2d/usedepth.md)                           | Sets the contact filter to filter the results by depth using [ContactFilter2D.minDepth](/engine/6000.0/script-reference/unityengine/contactfilter2d/mindepth.md) and [ContactFilter2D.maxDepth](/engine/6000.0/script-reference/unityengine/contactfilter2d/maxdepth.md).                                                |
| [useLayerMask](/engine/6000.0/script-reference/unityengine/contactfilter2d/uselayermask.md)                   | Sets the contact filter to filter results by layer mask.                                                                                                                                                                                                                                                                 |
| [useNormalAngle](/engine/6000.0/script-reference/unityengine/contactfilter2d/usenormalangle.md)               | Sets the contact filter to filter the results by the collision's normal angle using [ContactFilter2D.minNormalAngle](/engine/6000.0/script-reference/unityengine/contactfilter2d/minnormalangle.md) and [ContactFilter2D.maxNormalAngle](/engine/6000.0/script-reference/unityengine/contactfilter2d/maxnormalangle.md). |
| [useOutsideDepth](/engine/6000.0/script-reference/unityengine/contactfilter2d/useoutsidedepth.md)             | Sets the contact filter to filter within the [ContactFilter2D.minDepth](/engine/6000.0/script-reference/unityengine/contactfilter2d/mindepth.md) and [ContactFilter2D.maxDepth](/engine/6000.0/script-reference/unityengine/contactfilter2d/maxdepth.md) range, or outside that range.                                   |
| [useOutsideNormalAngle](/engine/6000.0/script-reference/unityengine/contactfilter2d/useoutsidenormalangle.md) | Sets the contact filter to filter within the [ContactFilter2D.minNormalAngle](/engine/6000.0/script-reference/unityengine/contactfilter2d/minnormalangle.md) and [ContactFilter2D.maxNormalAngle](/engine/6000.0/script-reference/unityengine/contactfilter2d/maxnormalangle.md) range, or outside that range.           |
| [useTriggers](/engine/6000.0/script-reference/unityengine/contactfilter2d/usetriggers.md)                     | Sets to filter contact results based on trigger collider involvement.                                                                                                                                                                                                                                                    |

## Properties

| Property                                                                                  | Description                                                                                |
| ----------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------ |
| [isFiltering](/engine/6000.0/script-reference/unityengine/contactfilter2d/isfiltering.md) | Given the current state of the contact filter, determine whether it would filter anything. |

## Methods

| Method                                                                                                          | Description                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| --------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [ClearDepth](/engine/6000.0/script-reference/unityengine/contactfilter2d/cleardepth.md)                         | Turns off depth filtering by setting [ContactFilter2D.useDepth](/engine/6000.0/script-reference/unityengine/contactfilter2d/usedepth.md) to false.  The associated values of [ContactFilter2D.minDepth](/engine/6000.0/script-reference/unityengine/contactfilter2d/mindepth.md) and [ContactFilter2D.maxDepth](/engine/6000.0/script-reference/unityengine/contactfilter2d/maxdepth.md) are not changed.                                           |
| [ClearLayerMask](/engine/6000.0/script-reference/unityengine/contactfilter2d/clearlayermask.md)                 | Turns off layer mask filtering by setting [ContactFilter2D.useLayerMask](/engine/6000.0/script-reference/unityengine/contactfilter2d/uselayermask.md) to false.  The associated value of [ContactFilter2D.layerMask](/engine/6000.0/script-reference/unityengine/contactfilter2d/layermask.md) is not changed.                                                                                                                                      |
| [ClearNormalAngle](/engine/6000.0/script-reference/unityengine/contactfilter2d/clearnormalangle.md)             | Turns off normal angle filtering by setting [ContactFilter2D.useNormalAngle](/engine/6000.0/script-reference/unityengine/contactfilter2d/usenormalangle.md) to false. The associated values of [ContactFilter2D.minNormalAngle](/engine/6000.0/script-reference/unityengine/contactfilter2d/minnormalangle.md) and [ContactFilter2D.maxNormalAngle](/engine/6000.0/script-reference/unityengine/contactfilter2d/maxnormalangle.md) are not changed. |
| [IsFilteringDepth](/engine/6000.0/script-reference/unityengine/contactfilter2d/isfilteringdepth.md)             | Checks if the [Transform](/engine/6000.0/script-reference/unityengine/transform.md) for obj is within the depth range to be filtered.                                                                                                                                                                                                                                                                                                               |
| [IsFilteringLayerMask](/engine/6000.0/script-reference/unityengine/contactfilter2d/isfilteringlayermask.md)     | Checks if the [GameObject.layer](/engine/6000.0/script-reference/unityengine/gameobject/layer.md) for obj is included in the [ContactFilter2D.layerMask](/engine/6000.0/script-reference/unityengine/contactfilter2d/layermask.md) to be filtered.                                                                                                                                                                                                  |
| [IsFilteringNormalAngle](/engine/6000.0/script-reference/unityengine/contactfilter2d/isfilteringnormalangle.md) | Checks if the angle is within the normal angle range to be filtered.                                                                                                                                                                                                                                                                                                                                                                                |
| [IsFilteringTrigger](/engine/6000.0/script-reference/unityengine/contactfilter2d/isfilteringtrigger.md)         | Checks if the collider is a trigger and should be filtered by the [ContactFilter2D.useTriggers](/engine/6000.0/script-reference/unityengine/contactfilter2d/usetriggers.md) to be filtered.                                                                                                                                                                                                                                                         |
| [NoFilter](/engine/6000.0/script-reference/unityengine/contactfilter2d/nofilter.md)                             | Sets the contact filter to not filter any [ContactPoint2D](/engine/6000.0/script-reference/unityengine/contactpoint2d.md).                                                                                                                                                                                                                                                                                                                          |
| [SetDepth](/engine/6000.0/script-reference/unityengine/contactfilter2d/setdepth.md)                             | Sets the [ContactFilter2D.minDepth](/engine/6000.0/script-reference/unityengine/contactfilter2d/mindepth.md) and [ContactFilter2D.maxDepth](/engine/6000.0/script-reference/unityengine/contactfilter2d/maxdepth.md) filter properties and turns on depth filtering by setting [ContactFilter2D.useDepth](/engine/6000.0/script-reference/unityengine/contactfilter2d/usedepth.md) to true.                                                         |
| [SetLayerMask](/engine/6000.0/script-reference/unityengine/contactfilter2d/setlayermask.md)                     | Sets the [ContactFilter2D.layerMask](/engine/6000.0/script-reference/unityengine/contactfilter2d/layermask.md) filter property using the *layerMask* parameter provided and also enables layer mask filtering by setting [ContactFilter2D.useLayerMask](/engine/6000.0/script-reference/unityengine/contactfilter2d/uselayermask.md) to true.                                                                                                       |
| [SetNormalAngle](/engine/6000.0/script-reference/unityengine/contactfilter2d/setnormalangle.md)                 | Sets the [ContactFilter2D.minNormalAngle](/engine/6000.0/script-reference/unityengine/contactfilter2d/minnormalangle.md) and [ContactFilter2D.maxNormalAngle](/engine/6000.0/script-reference/unityengine/contactfilter2d/maxnormalangle.md) filter properties and turns on normal angle filtering by setting [ContactFilter2D.useNormalAngle](/engine/6000.0/script-reference/unityengine/contactfilter2d/usenormalangle.md) to true.              |
