DestroyShapeBatch
Destroy a batch of shapes, destroying all PhysicsShape.Contact the shapes are involved in. Any invalid shapes will be ignored including chain segment shapes created via a PhysicsChain (the chain must be destroyed)." Owned shapes will produce a warning and will not be destroyed ( PhysicsShape.SetOwner ). See PhysicsBody.MassConfiguration.
Read time 2 minutesLast updated 13 days ago
Definition
- Type: Method
- Namespace: Unity.U2D.Physics
- Assembly: UnityEngine.PhysicsCore2DModule
DestroyShapeBatch(ReadOnlySpan<PhysicsShape>, bool)
Destroy a batch of shapes, destroying all PhysicsShape.Contact the shapes are involved in. Any invalid shapes will be ignored including chain segment shapes created via a PhysicsChain (the chain must be destroyed)." Owned shapes will produce a warning and will not be destroyed (PhysicsShape.SetOwner). See PhysicsBody.MassConfiguration.
public static void DestroyShapeBatch(ReadOnlySpan<PhysicsShape> shapes, bool updateBodyMass)
Parameters
The shapes to destroy.
Whether to update the body mass configuration. Not doing so is faster, especially when destroying multiple shapes.
Remarks
Use this method to destroy the shapes you create with PhysicsBody.CreateShapeBatch.
Examples
// Destroy a batch of shapes created with CreateShapeBatch.using UnityEngine;using Unity.Collections;using Unity.U2D.Physics;public class DestroyShapeBatchExample : MonoBehaviour{ void Start() { PhysicsWorld world = PhysicsWorld.defaultWorld; PhysicsBody body = world.CreateBody(); using NativeArray<CircleGeometry> circleGeometries = new NativeArray<CircleGeometry>( new[] { new CircleGeometry { radius = 1f } }, Allocator.Temp); NativeArray<PhysicsShape> shapes = body.CreateShapeBatch(circleGeometries, PhysicsShapeDefinition.defaultDefinition); PhysicsWorld.DestroyShapeBatch(shapes, updateBodyMass: true); shapes.Dispose(); }}
DestroyShapeBatch(ReadOnlySpan<PhysicsShape>, bool, int)
Destroy a batch of shapes, destroying all contacts the shapes are involved in. Any invalid shapes are ignored, including chain segment shapes created by a chain, which must be destroyed through their owning chain instead. A shape owned by a different owner key is skipped and left valid; a shape with no owner, or one matching the given owner key, is destroyed. One summary warning reports how many shapes were skipped this way, rather than one warning per shape.
public static void DestroyShapeBatch(ReadOnlySpan<PhysicsShape> shapes, bool updateBodyMass, int ownerKey)
Parameters
The shapes to destroy.
Whether to update the body mass configuration. Not doing so is faster, especially when destroying multiple shapes.
Optional owner key returned when using PhysicsShape.SetOwner.