Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


CreateBatch

Create a batch of bodies in the specified world.
Read time 3 minutesLast updated 10 days ago

Definition

  • Type: Method
  • Namespace: Unity.U2D.Physics
  • Assembly: UnityEngine.PhysicsCore2DModule

CreateBatch(PhysicsWorld, PhysicsBodyDefinition, int, Allocator)

Create a batch of bodies in the specified world.
public static NativeArray<PhysicsBody> CreateBatch(PhysicsWorld world, PhysicsBodyDefinition definition, int bodyCount, Allocator allocator = Allocator.Temp)

Parameters

The world to create the bodies in.

The body definition to use for all bodies.

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.

Returns

Type

Description

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.

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

Create a batch of bodies in the specified world, assigning the given owner to every created body.
public static NativeArray<PhysicsBody> CreateBatch(PhysicsWorld world, PhysicsBodyDefinition definition, int bodyCount, Object owner, int ownerKey, Allocator allocator = Allocator.Temp)

Parameters

The world to create the bodies in.

The body definition to use for all bodies.

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.

Returns

Type

Description

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.

Remarks

CreateBatch(PhysicsWorld, ReadOnlySpan<PhysicsBodyDefinition>, Allocator)

Create a batch of bodies in the specified world.
public static NativeArray<PhysicsBody> CreateBatch(PhysicsWorld world, ReadOnlySpan<PhysicsBodyDefinition> definitions, Allocator allocator = Allocator.Temp)

Parameters

The world to create the bodies in.

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.

Returns

Type

Description

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.

CreateBatch(PhysicsWorld, ReadOnlySpan<PhysicsBodyDefinition>, Object, int, Allocator)

Create a batch of bodies in the specified world, assigning the given owner to every created body.
public static NativeArray<PhysicsBody> CreateBatch(PhysicsWorld world, ReadOnlySpan<PhysicsBodyDefinition> definitions, Object owner, int ownerKey, Allocator allocator = Allocator.Temp)

Parameters

The world to create the bodies in.

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.

Returns

Type

Description

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.

Remarks