# GetData

> Read data values from the buffer into an array. The array can only use blittable types.

## Definition

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

## GetData(Array)

Read data values from the buffer into an array. The array can only use [blittable](https://docs.microsoft.com/en-us/dotnet/framework/interop/blittable-and-non-blittable-types) types.

```csharp
[SecurityCritical]
public void GetData(Array data)
```

### Parameters

**** (\[Array]\(https\://learn.microsoft.com/dotnet/api/system.array)): An array to receive the data.

### Remarks

The retrieved data will follow the data layout rules of the graphics API in use. See [Compute Shaders](/engine/6000.0/manual/materials-and-shaders/shaders/writing-custom/class-compute-shader.md) for cross-platform compatibility information.

Note that this function reads the data back from the GPU, which can be slow. If any GPU work has been submitted that writes to this buffer, Unity waits for the tasks to complete before it retrieves the requested data, guaranteeing this function returns the most up to date results. For this reason, you should use [AsyncGPUReadback](/engine/6000.0/script-reference/unityengine/rendering/asyncgpureadback.md) instead because it performs the request in the background, and allows you to check when the result is available, without blocking the main thread.

Note: Only [blittable](https://docs.microsoft.com/en-us/dotnet/framework/interop/blittable-and-non-blittable-types) data types can be copied from the buffer to the array, the array's type must be a blittable type. If you attempt to use non-blittable types, an exception will be raised.

Additional Resources: [ComputeBuffer.SetData](/engine/6000.0/script-reference/unityengine/computebuffer/setdata.md), [ComputeBuffer.count](/engine/6000.0/script-reference/unityengine/computebuffer/count.md), [ComputeBuffer.stride](/engine/6000.0/script-reference/unityengine/computebuffer/stride.md).

## GetData(Array, int, int, int)

Partial read of data values from the buffer into an array.

```csharp
[SecurityCritical]
public void GetData(Array data, int managedBufferStartIndex, int computeBufferStartIndex, int count)
```

### Parameters

**** (\[Array]\(https\://learn.microsoft.com/dotnet/api/system.array)): An array to receive the data.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The first element index in data where retrieved elements are copied.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The first element index of the compute buffer from which elements are read.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The number of elements to retrieve.

### Remarks

The retrieved data will follow the data layout rules of the graphics API in use. See [Compute Shaders](/engine/6000.0/manual/materials-and-shaders/shaders/writing-custom/class-compute-shader.md) for cross-platform compatibility information.

Note: Only [blittable](https://docs.microsoft.com/en-us/dotnet/framework/interop/blittable-and-non-blittable-types) data types can be copied from the buffer to the array, the array's type must be a blittable type. If you attempt to use non-blittable types, an exception will be raised.

Additional Resources: [ComputeBuffer.SetData](/engine/6000.0/script-reference/unityengine/computebuffer/setdata.md), [ComputeBuffer.count](/engine/6000.0/script-reference/unityengine/computebuffer/count.md), [ComputeBuffer.stride](/engine/6000.0/script-reference/unityengine/computebuffer/stride.md).
