| Parameter | Description |
|---|---|
| definition | The body definition to use. |
| bodyCount | The number of bodies to create. |
| allocator | The memory allocator to use for the results. This can only be Allocator.Temp, Allocator.TempJob or Allocator.Persistent. |
NativeArray<PhysicsBody> 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.
Create a batch of bodies in the world.
Use this method to create many bodies that share the same configuration, instead of calling PhysicsWorld.CreateBody in a loop.
// Create 500 bodies using a single definition. using UnityEngine; using Unity.Collections; using Unity.U2D.Physics;
public class CreateBodyBatchExample : MonoBehaviour { public PhysicsBodyDefinition bodyDefinition = PhysicsBodyDefinition.defaultDefinition;
void Start() { PhysicsWorld world = PhysicsWorld.defaultWorld; using NativeArray<PhysicsBody> fiveHundredBodies = world.CreateBodyBatch(bodyDefinition, 500); } }
| Parameter | Description |
|---|---|
| definition | The body definition to use. |
| bodyCount | The number of bodies to create. |
| owner | The owner object to assign to every created body. If null, no owner is assigned. |
| ownerKey | The owner key to assign. Must be non-zero when owner is not null. See PhysicsWorld.CreateOwnerKey. |
| allocator | The memory allocator to use for the results. This can only be Allocator.Temp, Allocator.TempJob or Allocator.Persistent. |
NativeArray<PhysicsBody> 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.
Create a batch of bodies in the world, assigning the given owner to every created body.
See PhysicsBody.SetOwner.
| Parameter | Description |
|---|---|
| definitions | The definitions used to create the bodies. The number of bodies produced is implicitly controlled by the number of definitions in this span. |
| allocator | The memory allocator to use for the results. This can only be Allocator.Temp, Allocator.TempJob or Allocator.Persistent. |
NativeArray<PhysicsBody> 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.
Create a batch of bodies in the world.
| Parameter | Description |
|---|---|
| definitions | The definitions used to create the bodies. The number of bodies produced is implicitly controlled by the number of definitions in this span. |
| owner | The owner object to assign to every created body. If null, no owner is assigned. |
| ownerKey | The owner key to assign. Must be non-zero when owner is not null. See PhysicsWorld.CreateOwnerKey. |
| allocator | The memory allocator to use for the results. This can only be Allocator.Temp, Allocator.TempJob or Allocator.Persistent. |
NativeArray<PhysicsBody> 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.
Create a batch of bodies in the world, assigning the given owner to every created body.
See PhysicsBody.SetOwner.