DestroyBodyBatch
Destroy a batch of bodies. Any invalid bodies will be ignored. Owned bodies will produce a warning and will not be destroyed (See PhysicsBody.SetOwner ).
Read time 1 minuteLast updated 10 days ago
Definition
- Type: Method
- Namespace: Unity.U2D.Physics
- Assembly: UnityEngine.PhysicsCore2DModule
DestroyBodyBatch(ReadOnlySpan<PhysicsBody>)
Destroy a batch of bodies. Any invalid bodies will be ignored. Owned bodies will produce a warning and will not be destroyed (See PhysicsBody.SetOwner).
public static void DestroyBodyBatch(ReadOnlySpan<PhysicsBody> bodies)
Parameters
The bodies to destroy.
Remarks
Use this method to destroy the bodies you create with PhysicsWorld.CreateBodyBatch.
Examples
// Destroy a batch of bodies created with CreateBodyBatch.using UnityEngine;using Unity.Collections;using Unity.U2D.Physics;public class DestroyBodyBatchExample : MonoBehaviour{ public PhysicsBodyDefinition bodyDefinition = PhysicsBodyDefinition.defaultDefinition; void Start() { PhysicsWorld world = PhysicsWorld.defaultWorld; NativeArray<PhysicsBody> bodies = world.CreateBodyBatch(bodyDefinition, 500); PhysicsWorld.DestroyBodyBatch(bodies); bodies.Dispose(); }}
DestroyBodyBatch(ReadOnlySpan<PhysicsBody>, int)
Destroy a batch of bodies. 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.
public static void DestroyBodyBatch(ReadOnlySpan<PhysicsBody> bodies, int ownerKey)
Parameters
Remarks
See PhysicsBody.SetOwner.