# SetBatchTransform

> Set the transform for a batch of PhysicsBody using a span of PhysicsBody.BatchTransform. If invalid values are passed to the batch, they will simply be ignored. For best performance, the bodies contained in the batch should all be part of the same PhysicsWorld. If the bodies in the batch are not contained in the same PhysicsWorld, the batch should be sorted by the PhysicsWorld the bodies are contained within.

## Definition

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

## SetBatchTransform(ReadOnlySpan\<BatchTransform>)

Set the transform for a batch of [PhysicsBody](/engine/6000.7/script-reference/unity/u2d/physics/physicsbody.md) using a span of [PhysicsBody.BatchTransform](/engine/6000.7/script-reference/unity/u2d/physics/physicsbody/batchtransform.md). If invalid values are passed to the batch, they will simply be ignored. For best performance, the bodies contained in the batch should all be part of the same [PhysicsWorld](/engine/6000.7/script-reference/unity/u2d/physics/physicsworld.md). If the bodies in the batch are not contained in the same [PhysicsWorld](/engine/6000.7/script-reference/unity/u2d/physics/physicsworld.md), the batch should be sorted by the [PhysicsWorld](/engine/6000.7/script-reference/unity/u2d/physics/physicsworld.md) the bodies are contained within.

```csharp
public static int SetBatchTransform(ReadOnlySpan<PhysicsBody.BatchTransform> batch)
```

### Parameters

**** (\[ReadOnlySpan\<BatchTransform>]\(https\://learn.microsoft.com/dotnet/api/system.readonlyspan-1)): The batch of bodies and values to set.

### Returns

| Type                                                       | Description                                                                                                                     |
| ---------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------- |
| [int](https://learn.microsoft.com/dotnet/api/system.int32) | The number of bodies that were ignored (not set because the body was invalid). A single warning is logged when any are ignored. |

## SetBatchTransform(ReadOnlySpan\<BatchTransform>, bool)

Set the transform for a batch of [PhysicsBody](/engine/6000.7/script-reference/unity/u2d/physics/physicsbody.md) using a span of [PhysicsBody.BatchTransform](/engine/6000.7/script-reference/unity/u2d/physics/physicsbody/batchtransform.md), optionally writing each pose to the [\_transformObject](/engine/6000.7/script-reference/unity/u2d/physics/physicsbody/transformobject.md) of its body. If invalid values are passed to the batch, they will simply be ignored. When `writePoses` is true, each pose set is also written to the [\_transformObject](/engine/6000.7/script-reference/unity/u2d/physics/physicsbody/transformobject.md) of its body, without producing a [PhysicsEvents.TransformChangeEvent](/engine/6000.7/script-reference/unity/u2d/physics/physicsevents/transformchangeevent.md). Writing poses requires all the valid bodies in the batch to be in the same [PhysicsWorld](/engine/6000.7/script-reference/unity/u2d/physics/physicsworld.md) and each to have its own [\_transformObject](/engine/6000.7/script-reference/unity/u2d/physics/physicsbody/transformobject.md) assigned, not shared with another body in the batch. Invalid bodies in the batch are still simply ignored. The \_transformWriteMode and \_transformWriteMode do not control this explicit write, except that [PhysicsWorld.TransformWriteMode.Fast2D](/engine/6000.7/script-reference/unity/u2d/physics/physicsworld/transformwritemode/fast2d.md) selects the faster rotation write. Writing poses must be done on the main thread.

```csharp
public static int SetBatchTransform(ReadOnlySpan<PhysicsBody.BatchTransform> batch, bool writePoses)
```

### Parameters

**** (\[ReadOnlySpan\<BatchTransform>]\(https\://learn.microsoft.com/dotnet/api/system.readonlyspan-1)): The batch of bodies and values to set.**** (\[bool]\(https\://learn.microsoft.com/dotnet/api/system.boolean)): Whether to also write the poses to the [\_transformObject](/engine/6000.7/script-reference/unity/u2d/physics/physicsbody/transformobject.md) of each body in the batch.

### Returns

| Type                                                       | Description                                                                                                                     |
| ---------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------- |
| [int](https://learn.microsoft.com/dotnet/api/system.int32) | The number of bodies that were ignored (not set because the body was invalid). A single warning is logged when any are ignored. |
