# SetPhysicsGroup(ReadOnlySpan<PhysicsShape>, PhysicsGroup)

> Set the same PhysicsWorld.PhysicsGroup on a batch of shapes. Each shape is assigned the group as PhysicsShape.physicsGroup would, and a shape that already has a group is left unchanged.

## Definition

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

```csharp
public static int SetPhysicsGroup(ReadOnlySpan<PhysicsShape> shapes, PhysicsWorld.PhysicsGroup physicsGroup)
```

### Parameters

**** (\[ReadOnlySpan\<PhysicsShape>]\(https\://learn.microsoft.com/dotnet/api/system.readonlyspan-1)): The shapes to set the group on.**** (\[PhysicsGroup]\(/engine/7000.0/script-reference/unity/u2d/physics/physicsworld/physicsgroup)): The group to set on every shape.

### Returns

| Type                                                       | Description                                                                                                                                                                                                                          |
| ---------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| [int](https://learn.microsoft.com/dotnet/api/system.int32) | The number of shapes that were ignored (not set because the shape was invalid or already had a group). A single warning is logged when any are ignored. If the group is empty, nothing is set and every shape is counted as ignored. |

### Remarks

Every shape given the same group must belong to the same body, otherwise the first and last marking of their events is unreliable. Shapes on more than one body are still assigned the group, and a single warning is logged. See [PhysicsWorld.PhysicsGroup](/engine/7000.0/script-reference/unity/u2d/physics/physicsworld/physicsgroup.md) and [PhysicsWorld.CreateGroup](/engine/7000.0/script-reference/unity/u2d/physics/physicsworld/creategroup.md).
