# SetBufferData

> Adds a command to set the buffer with values from an array.

## Definition

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

## SetBufferData(ComputeBuffer, Array)

Adds a command to set the buffer with values from an array.

```csharp
public void SetBufferData(ComputeBuffer buffer, Array data)
```

### Parameters

**** (\[ComputeBuffer]\(/engine/6000.0/script-reference/unityengine/computebuffer)): The destination buffer.**** (\[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.0/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.

## SetBufferData\<T>(ComputeBuffer, List\<T>)

Adds a command to set the buffer with values from an array.

```csharp
public void SetBufferData<T>(ComputeBuffer buffer, List<T> data) where T : struct
```

### Parameters

**** (\[ComputeBuffer]\(/engine/6000.0/script-reference/unityengine/computebuffer)): The destination buffer.**** (\[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.0/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.

## SetBufferData\<T>(ComputeBuffer, NativeArray\<T>)

Adds a command to set the buffer with values from an array.

```csharp
public void SetBufferData<T>(ComputeBuffer buffer, NativeArray<T> data) where T : struct
```

### Parameters

**** (\[ComputeBuffer]\(/engine/6000.0/script-reference/unityengine/computebuffer)): The destination buffer.**** (\[NativeArray\<T>]\(/engine/6000.0/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.0/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.

## SetBufferData(ComputeBuffer, Array, int, int, int)

Adds a command to process a partial copy of data values from an array into the buffer.

```csharp
public void SetBufferData(ComputeBuffer buffer, Array data, int managedBufferStartIndex, int graphicsBufferStartIndex, int count)
```

### Parameters

**** (\[ComputeBuffer]\(/engine/6000.0/script-reference/unityengine/computebuffer)): The destination buffer.**** (\[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.0/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.

## SetBufferData\<T>(ComputeBuffer, List\<T>, int, int, int)

Adds a command to process a partial copy of data values from an array into the buffer.

```csharp
public void SetBufferData<T>(ComputeBuffer buffer, List<T> data, int managedBufferStartIndex, int graphicsBufferStartIndex, int count) where T : struct
```

### Parameters

**** (\[ComputeBuffer]\(/engine/6000.0/script-reference/unityengine/computebuffer)): The destination buffer.**** (\[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.0/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.

## SetBufferData\<T>(ComputeBuffer, NativeArray\<T>, int, int, int)

Adds a command to process a partial copy of data values from an array into the buffer.

```csharp
public void SetBufferData<T>(ComputeBuffer buffer, NativeArray<T> data, int nativeBufferStartIndex, int graphicsBufferStartIndex, int count) where T : struct
```

### Parameters

**** (\[ComputeBuffer]\(/engine/6000.0/script-reference/unityengine/computebuffer)): The destination buffer.**** (\[NativeArray\<T>]\(/engine/6000.0/script-reference/unity/collections/nativearray1)): 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.0/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.

## SetBufferData(GraphicsBuffer, Array)

Adds a command to set the buffer with values from an array.

```csharp
public void SetBufferData(GraphicsBuffer buffer, Array data)
```

### Parameters

**** (\[GraphicsBuffer]\(/engine/6000.0/script-reference/unityengine/graphicsbuffer)): The destination buffer.**** (\[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.0/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.

## SetBufferData\<T>(GraphicsBuffer, List\<T>)

Adds a command to set the buffer with values from an array.

```csharp
public void SetBufferData<T>(GraphicsBuffer buffer, List<T> data) where T : struct
```

### Parameters

**** (\[GraphicsBuffer]\(/engine/6000.0/script-reference/unityengine/graphicsbuffer)): The destination buffer.**** (\[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.0/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.

## SetBufferData\<T>(GraphicsBuffer, NativeArray\<T>)

Adds a command to set the buffer with values from an array.

```csharp
public void SetBufferData<T>(GraphicsBuffer buffer, NativeArray<T> data) where T : struct
```

### Parameters

**** (\[GraphicsBuffer]\(/engine/6000.0/script-reference/unityengine/graphicsbuffer)): The destination buffer.**** (\[NativeArray\<T>]\(/engine/6000.0/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.0/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.

## SetBufferData(GraphicsBuffer, Array, int, int, int)

Adds a command to process a partial copy of data values from an array into the buffer.

```csharp
public void SetBufferData(GraphicsBuffer buffer, Array data, int managedBufferStartIndex, int graphicsBufferStartIndex, int count)
```

### Parameters

**** (\[GraphicsBuffer]\(/engine/6000.0/script-reference/unityengine/graphicsbuffer)): The destination buffer.**** (\[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.0/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.

## SetBufferData\<T>(GraphicsBuffer, List\<T>, int, int, int)

Adds a command to process a partial copy of data values from an array into the buffer.

```csharp
public void SetBufferData<T>(GraphicsBuffer buffer, List<T> data, int managedBufferStartIndex, int graphicsBufferStartIndex, int count) where T : struct
```

### Parameters

**** (\[GraphicsBuffer]\(/engine/6000.0/script-reference/unityengine/graphicsbuffer)): The destination buffer.**** (\[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.0/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.

## SetBufferData\<T>(GraphicsBuffer, NativeArray\<T>, int, int, int)

Adds a command to process a partial copy of data values from an array into the buffer.

```csharp
public void SetBufferData<T>(GraphicsBuffer buffer, NativeArray<T> data, int nativeBufferStartIndex, int graphicsBufferStartIndex, int count) where T : struct
```

### Parameters

**** (\[GraphicsBuffer]\(/engine/6000.0/script-reference/unityengine/graphicsbuffer)): The destination buffer.**** (\[NativeArray\<T>]\(/engine/6000.0/script-reference/unity/collections/nativearray1)): 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.0/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.
