# SetData

> Set the buffer with values from an array.

## Definition

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

## SetData(Array)

Set the buffer with values from an array.

```csharp
public void SetData(Array data)
```

### Parameters

**** (\[Array]\(https\://learn.microsoft.com/dotnet/api/system.array)): Array of values to fill the buffer.

### Remarks

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

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

Additional Resources: [ComputeBuffer.GetData](/engine/6000.6/script-reference/unityengine/computebuffer/getdata.md), [ComputeBuffer.count](/engine/6000.6/script-reference/unityengine/computebuffer/count.md), [ComputeBuffer.stride](/engine/6000.6/script-reference/unityengine/computebuffer/stride.md).

## SetData\<T>(List\<T>)

Set the buffer with values from an array.

```csharp
public void SetData<T>(List<T> data) where T : struct
```

### Parameters

**** (\[List\<T>]\(https\://learn.microsoft.com/dotnet/api/system.collections.generic.list-1)): Array of values to fill the buffer.

### Remarks

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

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

Additional Resources: [ComputeBuffer.GetData](/engine/6000.6/script-reference/unityengine/computebuffer/getdata.md), [ComputeBuffer.count](/engine/6000.6/script-reference/unityengine/computebuffer/count.md), [ComputeBuffer.stride](/engine/6000.6/script-reference/unityengine/computebuffer/stride.md).

## SetData\<T>(NativeArray\<T>)

Set the buffer with values from an array.

```csharp
public void SetData<T>(NativeArray<T> data) where T : struct
```

### Parameters

**** (\[NativeArray\<T>]\(/engine/6000.6/script-reference/unity/collections/nativearray1)): Array of values to fill the buffer.

### Remarks

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

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

Additional Resources: [ComputeBuffer.GetData](/engine/6000.6/script-reference/unityengine/computebuffer/getdata.md), [ComputeBuffer.count](/engine/6000.6/script-reference/unityengine/computebuffer/count.md), [ComputeBuffer.stride](/engine/6000.6/script-reference/unityengine/computebuffer/stride.md).

## SetData(Array, int, int, int)

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

```csharp
public void SetData(Array data, int managedBufferStartIndex, int computeBufferStartIndex, int count)
```

### Parameters

**** (\[Array]\(https\://learn.microsoft.com/dotnet/api/system.array)): Array of values to fill the buffer.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The first element index in data to copy to the compute buffer.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The first element index in compute buffer to receive the data.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The number of elements to copy.

### Remarks

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

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

Additional Resources: [ComputeBuffer.GetData](/engine/6000.6/script-reference/unityengine/computebuffer/getdata.md), [ComputeBuffer.count](/engine/6000.6/script-reference/unityengine/computebuffer/count.md), [ComputeBuffer.stride](/engine/6000.6/script-reference/unityengine/computebuffer/stride.md).

## SetData\<T>(List\<T>, int, int, int)

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

```csharp
public void SetData<T>(List<T> data, int managedBufferStartIndex, int computeBufferStartIndex, int count) where T : struct
```

### Parameters

**** (\[List\<T>]\(https\://learn.microsoft.com/dotnet/api/system.collections.generic.list-1)): Array of values to fill the buffer.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The first element index in data to copy to the compute buffer.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The first element index in compute buffer to receive the data.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The number of elements to copy.

### Remarks

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

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

Additional Resources: [ComputeBuffer.GetData](/engine/6000.6/script-reference/unityengine/computebuffer/getdata.md), [ComputeBuffer.count](/engine/6000.6/script-reference/unityengine/computebuffer/count.md), [ComputeBuffer.stride](/engine/6000.6/script-reference/unityengine/computebuffer/stride.md).

## SetData\<T>(NativeArray\<T>, int, int, int)

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

```csharp
public void SetData<T>(NativeArray<T> data, int nativeBufferStartIndex, int computeBufferStartIndex, int count) where T : struct
```

### Parameters

**** (\[NativeArray\<T>]\(/engine/6000.6/script-reference/unity/collections/nativearray1)): Array of values to fill the buffer.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): **** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The first element index in compute buffer to receive the data.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The number of elements to copy.

### Remarks

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

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

Additional Resources: [ComputeBuffer.GetData](/engine/6000.6/script-reference/unityengine/computebuffer/getdata.md), [ComputeBuffer.count](/engine/6000.6/script-reference/unityengine/computebuffer/count.md), [ComputeBuffer.stride](/engine/6000.6/script-reference/unityengine/computebuffer/stride.md).
