# GetShapeData

> Gets a copy of both the shapes and vertices in the PhysicsShapeGroup2D.

## Definition

* **Type:** Method
* **Namespace:** [UnityEngine](/engine/6000.6/script-reference/unityengine.md)
* **Assembly:** UnityEngine.Physics2DModule

## GetShapeData(List\<PhysicsShape2D>, List\<Vector2>)

Gets a copy of both the shapes and vertices in the [PhysicsShapeGroup2D](/engine/6000.6/script-reference/unityengine/physicsshapegroup2d.md).

```csharp
public void GetShapeData(List<PhysicsShape2D> shapes, List<Vector2> vertices)
```

### Parameters

**** (\[List\<PhysicsShape2D>]\(https\://learn.microsoft.com/dotnet/api/system.collections.generic.list-1)): A list that will be populated with a copy of all the shapes in the [PhysicsShapeGroup2D](/engine/6000.6/script-reference/unityengine/physicsshapegroup2d.md).**** (\[List\<Vector2>]\(https\://learn.microsoft.com/dotnet/api/system.collections.generic.list-1)): A list that will be populated with a copy of all the vertices in the [PhysicsShapeGroup2D](/engine/6000.6/script-reference/unityengine/physicsshapegroup2d.md).

### Remarks

**NOTE**: Because this is a copy, changing the specified `shapes` and `vertices` lists afterwards will not change the [PhysicsShapeGroup2D](/engine/6000.6/script-reference/unityengine/physicsshapegroup2d.md).

### Examples

```csharp
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Assertions;

public class Example : MonoBehaviour
{
    void Start()
    {
        // Create a shape group.
        var shapeGroup = new PhysicsShapeGroup2D();

        // Add a Circle to the shape group.
        var circleShapeIndex = shapeGroup.AddCircle
            (
                center: new Vector2(-2f, 3f),
                radius: 1f
            );

        // Add a Capsule to the shape group.
        var capsuleShapeIndex = shapeGroup.AddCapsule
            (
                vertex0: Vector2.down,
                vertex1: Vector2.up,
                radius: 0.5f
            );

        // Validate the contents.
        Assert.AreEqual(PhysicsShapeType2D.Circle, shapeGroup.GetShape(circleShapeIndex).shapeType);
        Assert.AreEqual(PhysicsShapeType2D.Capsule, shapeGroup.GetShape(capsuleShapeIndex).shapeType);

        // Fetch the shapes and vertices from the shape group.
        var shapes = new List<PhysicsShape2D>();
        var vertices = new List<Vector2>();
        shapeGroup.GetShapeData(shapes, vertices);

        // Fetch the Circle shape and validate shape and vertex.
        var circleShape = shapes[circleShapeIndex];
        Assert.AreEqual(PhysicsShapeType2D.Circle, circleShape.shapeType);
        Assert.AreApproximatelyEqual(1f, circleShape.radius);
        Assert.AreEqual(new Vector2(-2f, 3f), vertices[circleShape.vertexStartIndex]);

        // Fetch the Capsule shape and validate shape and vertices (2).
        var capsuleShape = shapes[capsuleShapeIndex];
        Assert.AreEqual(PhysicsShapeType2D.Capsule, capsuleShape.shapeType);
        Assert.AreApproximatelyEqual(0.5f, capsuleShape.radius);
        Assert.AreEqual(Vector2.down, vertices[capsuleShape.vertexStartIndex]);
        Assert.AreEqual(Vector2.up, vertices[capsuleShape.vertexStartIndex + 1]);
    }
}
```

## GetShapeData(NativeArray\<PhysicsShape2D>, NativeArray\<Vector2>)

Gets a copy of both the shapes and vertices in the [PhysicsShapeGroup2D](/engine/6000.6/script-reference/unityengine/physicsshapegroup2d.md).

```csharp
public void GetShapeData(NativeArray<PhysicsShape2D> shapes, NativeArray<Vector2> vertices)
```

### Parameters

**** (\[NativeArray\<PhysicsShape2D>]\(/engine/6000.6/script-reference/unity/collections/nativearray1)): A NativeArray that will be populated with a copy of all the shapes in the [PhysicsShapeGroup2D](/engine/6000.6/script-reference/unityengine/physicsshapegroup2d.md).**** (\[NativeArray\<Vector2>]\(/engine/6000.6/script-reference/unity/collections/nativearray1)): A NativeArray that will be populated with a copy of all the vertices in the [PhysicsShapeGroup2D](/engine/6000.6/script-reference/unityengine/physicsshapegroup2d.md).

### Remarks

**NOTE**: Because this is a copy, changing the specified `shapes` and `vertices` arrays afterwards will not change the [PhysicsShapeGroup2D](/engine/6000.6/script-reference/unityengine/physicsshapegroup2d.md).

### Examples

```csharp
using Unity.Collections;
using UnityEngine;
using UnityEngine.Assertions;

public class Example : MonoBehaviour
{
    void Start()
    {
        // Create a shape group.
        var shapeGroup = new PhysicsShapeGroup2D();

        // Add a Circle to the shape group.
        var circleShapeIndex = shapeGroup.AddCircle
            (
                center: new Vector2(-2f, 3f),
                radius: 1f
            );

        // Add a Capsule to the shape group.
        var capsuleShapeIndex = shapeGroup.AddCapsule
            (
                vertex0: Vector2.down,
                vertex1: Vector2.up,
                radius: 0.5f
            );

        // Validate the contents.
        Assert.AreEqual(PhysicsShapeType2D.Circle, shapeGroup.GetShape(circleShapeIndex).shapeType);
        Assert.AreEqual(PhysicsShapeType2D.Capsule, shapeGroup.GetShape(capsuleShapeIndex).shapeType);

        // Fetch the shapes and vertices from the shape group.
        var shapes = new NativeArray<PhysicsShape2D>(shapeGroup.shapeCount, Allocator.Temp);
        var vertices = new NativeArray<Vector2>(shapeGroup.vertexCount, Allocator.Temp);
        shapeGroup.GetShapeData(shapes, vertices);

        // Fetch the Circle shape and validate shape and vertex.
        var circleShape = shapes[circleShapeIndex];
        Assert.AreEqual(PhysicsShapeType2D.Circle, circleShape.shapeType);
        Assert.AreApproximatelyEqual(1f, circleShape.radius);
        Assert.AreEqual(new Vector2(-2f, 3f), vertices[circleShape.vertexStartIndex]);

        // Fetch the Capsule shape and validate shape and vertices (2).
        var capsuleShape = shapes[capsuleShapeIndex];
        Assert.AreEqual(PhysicsShapeType2D.Capsule, capsuleShape.shapeType);
        Assert.AreApproximatelyEqual(0.5f, capsuleShape.radius);
        Assert.AreEqual(Vector2.down, vertices[capsuleShape.vertexStartIndex]);
        Assert.AreEqual(Vector2.up, vertices[capsuleShape.vertexStartIndex + 1]);

        // Dispose of the native arrays.
        vertices.Dispose();
        shapes.Dispose();
    }
}
```
