# SetUserData

> Set PhysicsUserData on a batch of bodies that can be used for any purpose. The bodies and userDatas spans must be the same length; bodies[n] receives userDatas[n].

## Definition

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

## SetUserData(ReadOnlySpan\<PhysicsBody>, ReadOnlySpan\<PhysicsUserData>)

Set [PhysicsUserData](/engine/6000.7/script-reference/unity/u2d/physics/physicsuserdata.md) on a batch of bodies that can be used for any purpose. The bodies and userDatas spans must be the same length; bodies\[n] receives userDatas\[n].

```csharp
public static int SetUserData(ReadOnlySpan<PhysicsBody> bodies, ReadOnlySpan<PhysicsUserData> userDatas)
```

### Parameters

**** (\[ReadOnlySpan\<PhysicsBody>]\(https\://learn.microsoft.com/dotnet/api/system.readonlyspan-1)): The bodies to set the user data on.**** (\[ReadOnlySpan\<PhysicsUserData>]\(https\://learn.microsoft.com/dotnet/api/system.readonlyspan-1)): The user data to set, one entry per body.

### 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. If the spans are different lengths, nothing is set and every body is counted as ignored. |

## SetUserData(ReadOnlySpan\<PhysicsBody>, PhysicsUserData)

Set the same [PhysicsUserData](/engine/6000.7/script-reference/unity/u2d/physics/physicsuserdata.md) on a batch of bodies that can be used for any purpose.

```csharp
public static int SetUserData(ReadOnlySpan<PhysicsBody> bodies, PhysicsUserData physicsUserData)
```

### Parameters

**** (\[ReadOnlySpan\<PhysicsBody>]\(https\://learn.microsoft.com/dotnet/api/system.readonlyspan-1)): The bodies to set the user data on.**** (\[PhysicsUserData]\(/engine/6000.7/script-reference/unity/u2d/physics/physicsuserdata)): The user data to set on every body.

### 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. |
