# SetColor

> Set a color property.

## Definition

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

## SetColor(string, Color)

Set a color property.

```csharp
public void SetColor(string name, Color value)
```

### Parameters

**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): The name of the property.**** (\[Color]\(/engine/6000.0/script-reference/unityengine/color)): The [Color](/engine/6000.0/script-reference/unityengine/color.md) value to set.

### Remarks

Adds a property to the block. If a color property with the given name already exists, the old value is replaced.

The color value is considered to be always set in sRGB space and is converted to linear if the active color space is linear. You need manual updating of the color value if you switch between color spaces.

```csharp
using UnityEngine;

// Draws 3 meshes with the same material but with different colors.
using UnityEngine;
public class ExampleClass : MonoBehaviour
{
    public Mesh mesh;
    public Material material;
    private MaterialPropertyBlock block;

    void Start()
    {
        block = new MaterialPropertyBlock();
    }

    void Update()
    {
        // setup render params
        RenderParams rp = new RenderParams(material) {matProps = block};

        // red mesh
        block.SetColor("_Color", Color.red);
        Graphics.RenderMesh(rp, mesh, 0, Matrix4x4.Translate(new Vector3(0, 0, 0)));

        // green mesh
        block.SetColor("_Color", Color.green);
        Graphics.RenderMesh(rp, mesh, 0, Matrix4x4.Translate(new Vector3(5, 0, 0)));

        // blue mesh
        block.SetColor("_Color", Color.blue);
        Graphics.RenderMesh(rp, mesh, 0, Matrix4x4.Translate(new Vector3(-5, 0, 0)));
    }
}
```

Function variant that takes nameID is faster. If you are changing properties with the same name repeatedly, use [Shader.PropertyToID](/engine/6000.0/script-reference/unityengine/shader/propertytoid.md) to get unique identifier for the name, and pass the identifier to SetColor.

```csharp
using UnityEngine;

// Draws 3 meshes with the same material but with different colors.
using UnityEngine;
public class ExampleClass : MonoBehaviour
{
    public Mesh mesh;
    public Material material;
    private MaterialPropertyBlock block;

    void Start()
    {
        block = new MaterialPropertyBlock();
    }

    void Update()
    {
        // setup render params
        RenderParams rp = new RenderParams(material) {matProps = block};

        // red mesh
        block.SetColor("_Color", Color.red);
        Graphics.RenderMesh(rp, mesh, 0, Matrix4x4.Translate(new Vector3(0, 0, 0)));

        // green mesh
        block.SetColor("_Color", Color.green);
        Graphics.RenderMesh(rp, mesh, 0, Matrix4x4.Translate(new Vector3(5, 0, 0)));

        // blue mesh
        block.SetColor("_Color", Color.blue);
        Graphics.RenderMesh(rp, mesh, 0, Matrix4x4.Translate(new Vector3(-5, 0, 0)));
    }
}
```

Additional Resources: [MaterialPropertyBlock.SetFloat](/engine/6000.0/script-reference/unityengine/materialpropertyblock/setfloat.md), [MaterialPropertyBlock.SetVector](/engine/6000.0/script-reference/unityengine/materialpropertyblock/setvector.md), [MaterialPropertyBlock.SetMatrix](/engine/6000.0/script-reference/unityengine/materialpropertyblock/setmatrix.md), [MaterialPropertyBlock.SetTexture](/engine/6000.0/script-reference/unityengine/materialpropertyblock/settexture.md).

## SetColor(int, Color)

Set a color property.

```csharp
public void SetColor(int nameID, Color value)
```

### Parameters

**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The name ID of the property retrieved by [Shader.PropertyToID](/engine/6000.0/script-reference/unityengine/shader/propertytoid.md).**** (\[Color]\(/engine/6000.0/script-reference/unityengine/color)): The [Color](/engine/6000.0/script-reference/unityengine/color.md) value to set.

### Remarks

Adds a property to the block. If a color property with the given name already exists, the old value is replaced.

The color value is considered to be always set in sRGB space and is converted to linear if the active color space is linear. You need manual updating of the color value if you switch between color spaces.

```csharp
using UnityEngine;

// Draws 3 meshes with the same material but with different colors.
using UnityEngine;
public class ExampleClass : MonoBehaviour
{
    public Mesh mesh;
    public Material material;
    private MaterialPropertyBlock block;

    void Start()
    {
        block = new MaterialPropertyBlock();
    }

    void Update()
    {
        // setup render params
        RenderParams rp = new RenderParams(material) {matProps = block};

        // red mesh
        block.SetColor("_Color", Color.red);
        Graphics.RenderMesh(rp, mesh, 0, Matrix4x4.Translate(new Vector3(0, 0, 0)));

        // green mesh
        block.SetColor("_Color", Color.green);
        Graphics.RenderMesh(rp, mesh, 0, Matrix4x4.Translate(new Vector3(5, 0, 0)));

        // blue mesh
        block.SetColor("_Color", Color.blue);
        Graphics.RenderMesh(rp, mesh, 0, Matrix4x4.Translate(new Vector3(-5, 0, 0)));
    }
}
```

Function variant that takes nameID is faster. If you are changing properties with the same name repeatedly, use [Shader.PropertyToID](/engine/6000.0/script-reference/unityengine/shader/propertytoid.md) to get unique identifier for the name, and pass the identifier to SetColor.

```csharp
using UnityEngine;

// Draws 3 meshes with the same material but with different colors.
using UnityEngine;
public class ExampleClass : MonoBehaviour
{
    public Mesh mesh;
    public Material material;
    private MaterialPropertyBlock block;

    void Start()
    {
        block = new MaterialPropertyBlock();
    }

    void Update()
    {
        // setup render params
        RenderParams rp = new RenderParams(material) {matProps = block};

        // red mesh
        block.SetColor("_Color", Color.red);
        Graphics.RenderMesh(rp, mesh, 0, Matrix4x4.Translate(new Vector3(0, 0, 0)));

        // green mesh
        block.SetColor("_Color", Color.green);
        Graphics.RenderMesh(rp, mesh, 0, Matrix4x4.Translate(new Vector3(5, 0, 0)));

        // blue mesh
        block.SetColor("_Color", Color.blue);
        Graphics.RenderMesh(rp, mesh, 0, Matrix4x4.Translate(new Vector3(-5, 0, 0)));
    }
}
```

Additional Resources: [MaterialPropertyBlock.SetFloat](/engine/6000.0/script-reference/unityengine/materialpropertyblock/setfloat.md), [MaterialPropertyBlock.SetVector](/engine/6000.0/script-reference/unityengine/materialpropertyblock/setvector.md), [MaterialPropertyBlock.SetMatrix](/engine/6000.0/script-reference/unityengine/materialpropertyblock/setmatrix.md), [MaterialPropertyBlock.SetTexture](/engine/6000.0/script-reference/unityengine/materialpropertyblock/settexture.md).
