# DestroyBatch

> Destroy a batch of bodies, destroying all attached PhysicsShape and PhysicsJoint. Any invalid bodies will be ignored. Owned bodies will produce a warning and will not be destroyed (See PhysicsBody.SetOwner ).

## Definition

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

## DestroyBatch(ReadOnlySpan\<PhysicsBody>)

Destroy a batch of bodies, destroying all attached [PhysicsShape](/engine/6000.7/script-reference/unity/u2d/physics/physicsshape.md) and [PhysicsJoint](/engine/6000.7/script-reference/unity/u2d/physics/physicsjoint.md). Any invalid bodies will be ignored. Owned bodies will produce a warning and will not be destroyed (See [PhysicsBody.SetOwner](/engine/6000.7/script-reference/unity/u2d/physics/physicsbody/setowner.md)).

```csharp
public static void DestroyBatch(ReadOnlySpan<PhysicsBody> bodies)
```

### Parameters

**** (\[ReadOnlySpan\<PhysicsBody>]\(https\://learn.microsoft.com/dotnet/api/system.readonlyspan-1)): The bodies to destroy.

### Examples

```csharp
// Destroy every body returned by a batch creation call.
using UnityEngine;
using Unity.Collections;
using Unity.U2D.Physics;

public class DestroyBatchExample : MonoBehaviour
{
    public PhysicsBodyDefinition bodyDefinition = PhysicsBodyDefinition.defaultDefinition;

    void Start()
    {
        PhysicsWorld world = PhysicsWorld.defaultWorld;
        NativeArray<PhysicsBody> bodies = world.CreateBodyBatch(bodyDefinition, 500);
        PhysicsBody.DestroyBatch(bodies);
        bodies.Dispose();
    }
}
```

## DestroyBatch(ReadOnlySpan\<PhysicsBody>, int)

Destroy a batch of bodies, destroying all attached shapes and joints. Any invalid bodies are ignored. A body owned by a different owner key is skipped and left valid; a body with no owner, or one matching the given owner key, is destroyed. One summary warning reports how many bodies were skipped this way, rather than one warning per body.

```csharp
public static void DestroyBatch(ReadOnlySpan<PhysicsBody> bodies, int ownerKey)
```

### Parameters

**** (\[ReadOnlySpan\<PhysicsBody>]\(https\://learn.microsoft.com/dotnet/api/system.readonlyspan-1)): The bodies to destroy.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): Optional owner key returned when using [PhysicsBody.SetOwner](/engine/6000.7/script-reference/unity/u2d/physics/physicsbody/setowner.md).

### Remarks

See [PhysicsShape](/engine/6000.7/script-reference/unity/u2d/physics/physicsshape.md), [PhysicsJoint](/engine/6000.7/script-reference/unity/u2d/physics/physicsjoint.md) and [PhysicsBody.SetOwner](/engine/6000.7/script-reference/unity/u2d/physics/physicsbody/setowner.md).
