# Fragment

> Fragment the specified target geometry using the specified fragment points. The fragment points define areas where polygon fragments will be produced from the target geometry. If the resulting polygon fragments have more polygon vertices than can fit into a single PolygonGeometry then the fragment will be split into multiple polygon fragments. The maximum number of vertices a single polygon fragment can have is defined by PhysicsConstants.MaxPolygonVertices. If even a single fragment point overlaps the target geometry then all results will be returned in _brokenGeometry. If none of the fragment points overlap the target geometry then all the results will be returned in _unbrokenGeometry. See PhysicsDestructor.FragmentResult.

## Definition

* **Type:** Method
* **Namespace:** [Unity.U2D.Physics](/engine/6000.7/script-reference/unity/u2d/physics.md)
* **Assembly:** UnityEngine.PhysicsCore2DModule

## Fragment(FragmentGeometry, ReadOnlySpan\<Vector2>, Allocator)

Fragment the specified target geometry using the specified fragment points.

The fragment points define areas where polygon fragments will be produced from the target geometry.

If the resulting polygon fragments have more polygon vertices than can fit into a single [PolygonGeometry](/engine/6000.7/script-reference/unity/u2d/physics/polygongeometry.md) then the fragment will be split into multiple polygon fragments. The maximum number of vertices a single polygon fragment can have is defined by [PhysicsConstants.MaxPolygonVertices](/engine/6000.7/script-reference/unity/u2d/physics/physicsconstants/maxpolygonvertices.md).

If even a single fragment point overlaps the target geometry then all results will be returned in [\_brokenGeometry](/engine/6000.7/script-reference/unity/u2d/physics/physicsdestructor/fragmentresult/brokengeometry.md). If none of the fragment points overlap the target geometry then all the results will be returned in [\_unbrokenGeometry](/engine/6000.7/script-reference/unity/u2d/physics/physicsdestructor/fragmentresult/unbrokengeometry.md). See [PhysicsDestructor.FragmentResult](/engine/6000.7/script-reference/unity/u2d/physics/physicsdestructor/fragmentresult.md).

```csharp
public static PhysicsDestructor.FragmentResult Fragment(PhysicsDestructor.FragmentGeometry target, ReadOnlySpan<Vector2> fragmentPoints, Allocator allocator = Allocator.Temp)
```

### Parameters

**** (\[FragmentGeometry]\(/engine/6000.7/script-reference/unity/u2d/physics/physicsdestructor/fragmentgeometry)): The target geometry to fragment. There must be at least a single geometry element. Any target polygons with a non-zero radius will be ignored.**** (\[ReadOnlySpan\<Vector2>]\(https\://learn.microsoft.com/dotnet/api/system.readonlyspan-1)): The world-space fragment points used to define fragment regions. The number of fragment points must be greater than 1.**** (\[Allocator]\(/engine/6000.7/script-reference/unity/collections/allocator)): The memory allocator to use for the results. This can only be [Allocator.Temp](/engine/6000.7/script-reference/unity/collections/allocator/temp.md), [Allocator.TempJob](/engine/6000.7/script-reference/unity/collections/allocator/tempjob.md) or [Allocator.Persistent](/engine/6000.7/script-reference/unity/collections/allocator/persistent.md).

### Returns

| Type                                                                                                    | Description                                                                                   |
| ------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------- |
| [FragmentResult](/engine/6000.7/script-reference/unity/u2d/physics/physicsdestructor/fragmentresult.md) | The fragment results. These results must be disposed of after use otherwise leaks will occur. |

## Fragment(FragmentGeometry, FragmentGeometry, ReadOnlySpan\<Vector2>, Allocator)

Fragment the specified mask geometry using the specified fragment points, after the target geometry has the mask (carving) geometry removed from it.

The target geometry is first clipped with the mask geometry using a [PhysicsComposer.Operation.NOT](/engine/6000.7/script-reference/unity/u2d/physics/physicscomposer/operation/not.md) operation. The resulting target geometry is returned in [\_unbrokenGeometry](/engine/6000.7/script-reference/unity/u2d/physics/physicsdestructor/fragmentresult/unbrokengeometry.md). The mask geometry is then clipped with the original target geometry using an [PhysicsComposer.Operation.AND](/engine/6000.7/script-reference/unity/u2d/physics/physicscomposer/operation/and.md) operation. If the clipped mask produces no geometry then no results are returned in [\_brokenGeometry](/engine/6000.7/script-reference/unity/u2d/physics/physicsdestructor/fragmentresult/brokengeometry.md).

The fragment points define areas where polygon fragments will be produced from the clipped masked geometry. The resulting polygon fragments are returned in [\_brokenGeometry](/engine/6000.7/script-reference/unity/u2d/physics/physicsdestructor/fragmentresult/brokengeometry.md).

If the resulting polygon fragments have more polygon vertices than can fit into a single [PolygonGeometry](/engine/6000.7/script-reference/unity/u2d/physics/polygongeometry.md) then the fragment will be split into multiple polygon fragments. The maximum number of vertices a single polygon fragment can have is defined by [PhysicsConstants.MaxPolygonVertices](/engine/6000.7/script-reference/unity/u2d/physics/physicsconstants/maxpolygonvertices.md). See [PhysicsDestructor.FragmentResult](/engine/6000.7/script-reference/unity/u2d/physics/physicsdestructor/fragmentresult.md).

```csharp
public static PhysicsDestructor.FragmentResult Fragment(PhysicsDestructor.FragmentGeometry target, PhysicsDestructor.FragmentGeometry mask, ReadOnlySpan<Vector2> fragmentPoints, Allocator allocator = Allocator.Temp)
```

### Parameters

**** (\[FragmentGeometry]\(/engine/6000.7/script-reference/unity/u2d/physics/physicsdestructor/fragmentgeometry)): The target geometry to fragment. There must be at least a single geometry element. Any target polygons with a non-zero radius will be ignored.**** (\[FragmentGeometry]\(/engine/6000.7/script-reference/unity/u2d/physics/physicsdestructor/fragmentgeometry)): The mask geometry that will be used to clip the target geometry. There must be at least a single geometry element. Any mask polygons with a non-zero radius will be ignored.**** (\[ReadOnlySpan\<Vector2>]\(https\://learn.microsoft.com/dotnet/api/system.readonlyspan-1)): The world-space fragment points used to define fragment regions. The number of fragment points must be greater than 1.**** (\[Allocator]\(/engine/6000.7/script-reference/unity/collections/allocator)): The memory allocator to use for the results. This can only be [Allocator.Temp](/engine/6000.7/script-reference/unity/collections/allocator/temp.md), [Allocator.TempJob](/engine/6000.7/script-reference/unity/collections/allocator/tempjob.md) or [Allocator.Persistent](/engine/6000.7/script-reference/unity/collections/allocator/persistent.md).

### Returns

| Type                                                                                                    | Description                                                                                                                                                           |
| ------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [FragmentResult](/engine/6000.7/script-reference/unity/u2d/physics/physicsdestructor/fragmentresult.md) | The fragment results. The transform returned here is the one provided in the target geometry. These results must be disposed of after use otherwise leaks will occur. |
