# CreateBatch

> Create a batch of bodies in the specified world.

## Definition

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

## CreateBatch(PhysicsWorld, PhysicsBodyDefinition, int, Allocator)

Create a batch of bodies in the specified world.

```csharp
public static NativeArray<PhysicsBody> CreateBatch(PhysicsWorld world, PhysicsBodyDefinition definition, int bodyCount, Allocator allocator = Allocator.Temp)
```

### Parameters

**** (\[PhysicsWorld]\(/engine/6000.5/script-reference/unity/u2d/physics/physicsworld)): The world to create the bodies in.**** (\[PhysicsBodyDefinition]\(/engine/6000.5/script-reference/unity/u2d/physics/physicsbodydefinition)): The body definition to use for all bodies.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The number of bodies to create.**** (\[Allocator]\(/engine/6000.5/script-reference/unity/collections/allocator)): The memory allocator to use for the results. This can only be [Allocator.Temp](/engine/6000.5/script-reference/unity/collections/allocator/temp.md), [Allocator.TempJob](/engine/6000.5/script-reference/unity/collections/allocator/tempjob.md) or [Allocator.Persistent](/engine/6000.5/script-reference/unity/collections/allocator/persistent.md).

### Returns

| Type                                                                                           | Description                                                                                                                                    |
| ---------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------- |
| [NativeArray\<PhysicsBody>](/engine/6000.5/script-reference/unity/collections/nativearray1.md) | The created bodies. This NativeArray must be disposed of after use otherwise leaks will occur. The exception to this is if the array is empty. |

## CreateBatch(PhysicsWorld, ReadOnlySpan\<PhysicsBodyDefinition>, Allocator)

Create a batch of bodies in the specified world.

```csharp
public static NativeArray<PhysicsBody> CreateBatch(PhysicsWorld world, ReadOnlySpan<PhysicsBodyDefinition> definitions, Allocator allocator = Allocator.Temp)
```

### Parameters

**** (\[PhysicsWorld]\(/engine/6000.5/script-reference/unity/u2d/physics/physicsworld)): The world to create the bodies in.**** (\[ReadOnlySpan\<PhysicsBodyDefinition>]\(https\://learn.microsoft.com/dotnet/api/system.readonlyspan-1)): The definitions used to create the bodies. The number of bodies produced is implicitly controlled by the number of definitions in this span.**** (\[Allocator]\(/engine/6000.5/script-reference/unity/collections/allocator)): The memory allocator to use for the results. This can only be [Allocator.Temp](/engine/6000.5/script-reference/unity/collections/allocator/temp.md), [Allocator.TempJob](/engine/6000.5/script-reference/unity/collections/allocator/tempjob.md) or [Allocator.Persistent](/engine/6000.5/script-reference/unity/collections/allocator/persistent.md).

### Returns

| Type                                                                                           | Description                                                                                                                                    |
| ---------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------- |
| [NativeArray\<PhysicsBody>](/engine/6000.5/script-reference/unity/collections/nativearray1.md) | The created bodies. This NativeArray must be disposed of after use otherwise leaks will occur. The exception to this is if the array is empty. |
