# SetConstantBuffer

> Sets a ComputeBuffer or GraphicsBuffer as a named constant buffer for the MaterialPropertyBlock.

## Definition

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

## SetConstantBuffer(string, ComputeBuffer, int, int)

Sets a [ComputeBuffer](/engine/6000.7/script-reference/unityengine/computebuffer.md) or [GraphicsBuffer](/engine/6000.7/script-reference/unityengine/graphicsbuffer.md) as a named constant buffer for the MaterialPropertyBlock.

```csharp
public void SetConstantBuffer(string name, ComputeBuffer value, int offset, int size)
```

### Parameters

**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): The name of the constant buffer to override.**** (\[ComputeBuffer]\(/engine/6000.7/script-reference/unityengine/computebuffer)): The buffer to override the constant buffer values with.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): Offset in bytes from the beginning of the buffer to bind. Must be a multiple of [SystemInfo.constantBufferOffsetAlignment](/engine/6000.7/script-reference/unityengine/systeminfo/constantbufferoffsetalignment.md), or 0 if that value is 0.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The number of bytes to bind.

### Remarks

Additional Resources: [Material.SetConstantBuffer](/engine/6000.7/script-reference/unityengine/material/setconstantbuffer.md).

## SetConstantBuffer(int, ComputeBuffer, int, int)

Sets a [ComputeBuffer](/engine/6000.7/script-reference/unityengine/computebuffer.md) or [GraphicsBuffer](/engine/6000.7/script-reference/unityengine/graphicsbuffer.md) as a named constant buffer for the MaterialPropertyBlock.

```csharp
public void SetConstantBuffer(int nameID, ComputeBuffer value, int offset, int size)
```

### Parameters

**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The shader property ID of the constant buffer to override.**** (\[ComputeBuffer]\(/engine/6000.7/script-reference/unityengine/computebuffer)): The buffer to override the constant buffer values with.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): Offset in bytes from the beginning of the buffer to bind. Must be a multiple of [SystemInfo.constantBufferOffsetAlignment](/engine/6000.7/script-reference/unityengine/systeminfo/constantbufferoffsetalignment.md), or 0 if that value is 0.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The number of bytes to bind.

### Remarks

Additional Resources: [Material.SetConstantBuffer](/engine/6000.7/script-reference/unityengine/material/setconstantbuffer.md).

## SetConstantBuffer(string, GraphicsBuffer, int, int)

Sets a [ComputeBuffer](/engine/6000.7/script-reference/unityengine/computebuffer.md) or [GraphicsBuffer](/engine/6000.7/script-reference/unityengine/graphicsbuffer.md) as a named constant buffer for the MaterialPropertyBlock.

```csharp
public void SetConstantBuffer(string name, GraphicsBuffer value, int offset, int size)
```

### Parameters

**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): The name of the constant buffer to override.**** (\[GraphicsBuffer]\(/engine/6000.7/script-reference/unityengine/graphicsbuffer)): The buffer to override the constant buffer values with.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): Offset in bytes from the beginning of the buffer to bind. Must be a multiple of [SystemInfo.constantBufferOffsetAlignment](/engine/6000.7/script-reference/unityengine/systeminfo/constantbufferoffsetalignment.md), or 0 if that value is 0.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The number of bytes to bind.

### Remarks

Additional Resources: [Material.SetConstantBuffer](/engine/6000.7/script-reference/unityengine/material/setconstantbuffer.md).

## SetConstantBuffer(int, GraphicsBuffer, int, int)

Sets a [ComputeBuffer](/engine/6000.7/script-reference/unityengine/computebuffer.md) or [GraphicsBuffer](/engine/6000.7/script-reference/unityengine/graphicsbuffer.md) as a named constant buffer for the MaterialPropertyBlock.

```csharp
public void SetConstantBuffer(int nameID, GraphicsBuffer value, int offset, int size)
```

### Parameters

**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The shader property ID of the constant buffer to override.**** (\[GraphicsBuffer]\(/engine/6000.7/script-reference/unityengine/graphicsbuffer)): The buffer to override the constant buffer values with.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): Offset in bytes from the beginning of the buffer to bind. Must be a multiple of [SystemInfo.constantBufferOffsetAlignment](/engine/6000.7/script-reference/unityengine/systeminfo/constantbufferoffsetalignment.md), or 0 if that value is 0.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The number of bytes to bind.

### Remarks

Additional Resources: [Material.SetConstantBuffer](/engine/6000.7/script-reference/unityengine/material/setconstantbuffer.md).
