# SetTexture

> Sets a named texture.

## Definition

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

## SetTexture(string, Texture)

Sets a named texture.

```csharp
public void SetTexture(string name, Texture value)
```

### Parameters

**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): Property name, e.g. "\_MainTex".**** (\[Texture]\(/engine/6000.7/script-reference/unityengine/texture)): Texture to set.

### Remarks

Many shaders use more than one texture. Use SetTexture to change the texture (identified by shader property name, or unique property name ID).

When setting textures on materials using the Standard Shader, you should be aware that you may need to use [Material.EnableKeyword](/engine/6000.7/script-reference/unityengine/material/enablekeyword.md) to enable features of the shader that were not previously in use. For more detail, read [Accessing Materials via Script](/engine/6000.7/manual/materials-and-shaders/materials/accessing-via-script.md).

Common texture names used by Unity's builtin shaders:

`"_MainTex"` is the main diffuse texture. This can also be accessed via [Material.mainTexture](/engine/6000.7/script-reference/unityengine/material/maintexture.md) property.

`"_BumpMap"` is the normal map.

The shader properties also show some of the keywords needed to set the Texture of a Material. To see this, go to your Material and right click on the **Shader** dropdown at the top. Next, pick **Select Shader**.

By specifying a `RenderTextureSubElement`, you can indicate which type of data to set from the RenderTexture. The possible options are: [RenderTextureSubElement.Color](/engine/6000.7/script-reference/unityengine/rendering/rendertexturesubelement/color.md), [RenderTextureSubElement.Depth](/engine/6000.7/script-reference/unityengine/rendering/rendertexturesubelement/depth.md), and [RenderTextureSubElement.Stencil](/engine/6000.7/script-reference/unityengine/rendering/rendertexturesubelement/stencil.md).

Additional Resources: [Material.mainTexture](/engine/6000.7/script-reference/unityengine/material/maintexture.md) property, [Material.GetTexture](/engine/6000.7/script-reference/unityengine/material/gettexture.md), [Shader.PropertyToID](/engine/6000.7/script-reference/unityengine/shader/propertytoid.md), [Properties in Shader Programs](/engine/6000.7/manual/materials-and-shaders/shaders/writing-custom/shader-writing/writing-shader-change-properties/sl-properties-in-programs.md), [RenderTextureSubElement](/engine/6000.7/script-reference/unityengine/rendering/rendertexturesubelement.md).

### Examples

```csharp
//Attach this script to your GameObject (make sure it has a Renderer component)
//Click on the GameObject. Attach your own Textures in the GameObject’s Inspector.

//This script takes your GameObject’s material and changes its Normal Map, Albedo, and Metallic properties to the Textures you attach in the GameObject’s Inspector. This happens when you enter Play Mode

using UnityEngine;

public class Example : MonoBehaviour {

    //Set these Textures in the Inspector
    public Texture m_MainTexture, m_Normal, m_Metal;
    Renderer m_Renderer;

    // Use this for initialization
    void Start () {
        //Fetch the Renderer from the GameObject
        m_Renderer = GetComponent<Renderer> ();

        //Make sure to enable the Keywords
        m_Renderer.material.EnableKeyword ("_NORMALMAP");
        m_Renderer.material.EnableKeyword ("_METALLICGLOSSMAP");

        //Set the Texture you assign in the Inspector as the main texture (Or Albedo)
        m_Renderer.material.SetTexture("_MainTex", m_MainTexture);
        //Set the Normal map using the Texture you assign in the Inspector
        m_Renderer.material.SetTexture("_BumpMap", m_Normal);
        //Set the Metallic Texture as a Texture you assign in the Inspector
        m_Renderer.material.SetTexture ("_MetallicGlossMap", m_Metal);
    }
}
```

## SetTexture(int, Texture)

Sets a named texture.

```csharp
public void SetTexture(int nameID, Texture value)
```

### Parameters

**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): Property name ID, use [Shader.PropertyToID](/engine/6000.7/script-reference/unityengine/shader/propertytoid.md) to get it.**** (\[Texture]\(/engine/6000.7/script-reference/unityengine/texture)): Texture to set.

### Remarks

Many shaders use more than one texture. Use SetTexture to change the texture (identified by shader property name, or unique property name ID).

When setting textures on materials using the Standard Shader, you should be aware that you may need to use [Material.EnableKeyword](/engine/6000.7/script-reference/unityengine/material/enablekeyword.md) to enable features of the shader that were not previously in use. For more detail, read [Accessing Materials via Script](/engine/6000.7/manual/materials-and-shaders/materials/accessing-via-script.md).

Common texture names used by Unity's builtin shaders:

`"_MainTex"` is the main diffuse texture. This can also be accessed via [Material.mainTexture](/engine/6000.7/script-reference/unityengine/material/maintexture.md) property.

`"_BumpMap"` is the normal map.

The shader properties also show some of the keywords needed to set the Texture of a Material. To see this, go to your Material and right click on the **Shader** dropdown at the top. Next, pick **Select Shader**.

By specifying a `RenderTextureSubElement`, you can indicate which type of data to set from the RenderTexture. The possible options are: [RenderTextureSubElement.Color](/engine/6000.7/script-reference/unityengine/rendering/rendertexturesubelement/color.md), [RenderTextureSubElement.Depth](/engine/6000.7/script-reference/unityengine/rendering/rendertexturesubelement/depth.md), and [RenderTextureSubElement.Stencil](/engine/6000.7/script-reference/unityengine/rendering/rendertexturesubelement/stencil.md).

Additional Resources: [Material.mainTexture](/engine/6000.7/script-reference/unityengine/material/maintexture.md) property, [Material.GetTexture](/engine/6000.7/script-reference/unityengine/material/gettexture.md), [Shader.PropertyToID](/engine/6000.7/script-reference/unityengine/shader/propertytoid.md), [Properties in Shader Programs](/engine/6000.7/manual/materials-and-shaders/shaders/writing-custom/shader-writing/writing-shader-change-properties/sl-properties-in-programs.md), [RenderTextureSubElement](/engine/6000.7/script-reference/unityengine/rendering/rendertexturesubelement.md).

### Examples

```csharp
//Attach this script to your GameObject (make sure it has a Renderer component)
//Click on the GameObject. Attach your own Textures in the GameObject’s Inspector.

//This script takes your GameObject’s material and changes its Normal Map, Albedo, and Metallic properties to the Textures you attach in the GameObject’s Inspector. This happens when you enter Play Mode

using UnityEngine;

public class Example : MonoBehaviour {

    //Set these Textures in the Inspector
    public Texture m_MainTexture, m_Normal, m_Metal;
    Renderer m_Renderer;

    // Use this for initialization
    void Start () {
        //Fetch the Renderer from the GameObject
        m_Renderer = GetComponent<Renderer> ();

        //Make sure to enable the Keywords
        m_Renderer.material.EnableKeyword ("_NORMALMAP");
        m_Renderer.material.EnableKeyword ("_METALLICGLOSSMAP");

        //Set the Texture you assign in the Inspector as the main texture (Or Albedo)
        m_Renderer.material.SetTexture("_MainTex", m_MainTexture);
        //Set the Normal map using the Texture you assign in the Inspector
        m_Renderer.material.SetTexture("_BumpMap", m_Normal);
        //Set the Metallic Texture as a Texture you assign in the Inspector
        m_Renderer.material.SetTexture ("_MetallicGlossMap", m_Metal);
    }
}
```

## SetTexture(string, RenderTexture, RenderTextureSubElement)

Sets a named texture.

```csharp
public void SetTexture(string name, RenderTexture value, RenderTextureSubElement element)
```

### Parameters

**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): Property name, e.g. "\_MainTex".**** (\[RenderTexture]\(/engine/6000.7/script-reference/unityengine/rendertexture)): Texture to set.**** (\[RenderTextureSubElement]\(/engine/6000.7/script-reference/unityengine/rendering/rendertexturesubelement)): Optional parameter that specifies the type of data to set from the RenderTexture.

### Remarks

Many shaders use more than one texture. Use SetTexture to change the texture (identified by shader property name, or unique property name ID).

When setting textures on materials using the Standard Shader, you should be aware that you may need to use [Material.EnableKeyword](/engine/6000.7/script-reference/unityengine/material/enablekeyword.md) to enable features of the shader that were not previously in use. For more detail, read [Accessing Materials via Script](/engine/6000.7/manual/materials-and-shaders/materials/accessing-via-script.md).

Common texture names used by Unity's builtin shaders:

`"_MainTex"` is the main diffuse texture. This can also be accessed via [Material.mainTexture](/engine/6000.7/script-reference/unityengine/material/maintexture.md) property.

`"_BumpMap"` is the normal map.

The shader properties also show some of the keywords needed to set the Texture of a Material. To see this, go to your Material and right click on the **Shader** dropdown at the top. Next, pick **Select Shader**.

By specifying a `RenderTextureSubElement`, you can indicate which type of data to set from the RenderTexture. The possible options are: [RenderTextureSubElement.Color](/engine/6000.7/script-reference/unityengine/rendering/rendertexturesubelement/color.md), [RenderTextureSubElement.Depth](/engine/6000.7/script-reference/unityengine/rendering/rendertexturesubelement/depth.md), and [RenderTextureSubElement.Stencil](/engine/6000.7/script-reference/unityengine/rendering/rendertexturesubelement/stencil.md).

Additional Resources: [Material.mainTexture](/engine/6000.7/script-reference/unityengine/material/maintexture.md) property, [Material.GetTexture](/engine/6000.7/script-reference/unityengine/material/gettexture.md), [Shader.PropertyToID](/engine/6000.7/script-reference/unityengine/shader/propertytoid.md), [Properties in Shader Programs](/engine/6000.7/manual/materials-and-shaders/shaders/writing-custom/shader-writing/writing-shader-change-properties/sl-properties-in-programs.md), [RenderTextureSubElement](/engine/6000.7/script-reference/unityengine/rendering/rendertexturesubelement.md).

### Examples

```csharp
//Attach this script to your GameObject (make sure it has a Renderer component)
//Click on the GameObject. Attach your own Textures in the GameObject’s Inspector.

//This script takes your GameObject’s material and changes its Normal Map, Albedo, and Metallic properties to the Textures you attach in the GameObject’s Inspector. This happens when you enter Play Mode

using UnityEngine;

public class Example : MonoBehaviour {

    //Set these Textures in the Inspector
    public Texture m_MainTexture, m_Normal, m_Metal;
    Renderer m_Renderer;

    // Use this for initialization
    void Start () {
        //Fetch the Renderer from the GameObject
        m_Renderer = GetComponent<Renderer> ();

        //Make sure to enable the Keywords
        m_Renderer.material.EnableKeyword ("_NORMALMAP");
        m_Renderer.material.EnableKeyword ("_METALLICGLOSSMAP");

        //Set the Texture you assign in the Inspector as the main texture (Or Albedo)
        m_Renderer.material.SetTexture("_MainTex", m_MainTexture);
        //Set the Normal map using the Texture you assign in the Inspector
        m_Renderer.material.SetTexture("_BumpMap", m_Normal);
        //Set the Metallic Texture as a Texture you assign in the Inspector
        m_Renderer.material.SetTexture ("_MetallicGlossMap", m_Metal);
    }
}
```

## SetTexture(int, RenderTexture, RenderTextureSubElement)

Sets a named texture.

```csharp
public void SetTexture(int nameID, RenderTexture value, RenderTextureSubElement element)
```

### Parameters

**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): Property name ID, use [Shader.PropertyToID](/engine/6000.7/script-reference/unityengine/shader/propertytoid.md) to get it.**** (\[RenderTexture]\(/engine/6000.7/script-reference/unityengine/rendertexture)): Texture to set.**** (\[RenderTextureSubElement]\(/engine/6000.7/script-reference/unityengine/rendering/rendertexturesubelement)): Optional parameter that specifies the type of data to set from the RenderTexture.

### Remarks

Many shaders use more than one texture. Use SetTexture to change the texture (identified by shader property name, or unique property name ID).

When setting textures on materials using the Standard Shader, you should be aware that you may need to use [Material.EnableKeyword](/engine/6000.7/script-reference/unityengine/material/enablekeyword.md) to enable features of the shader that were not previously in use. For more detail, read [Accessing Materials via Script](/engine/6000.7/manual/materials-and-shaders/materials/accessing-via-script.md).

Common texture names used by Unity's builtin shaders:

`"_MainTex"` is the main diffuse texture. This can also be accessed via [Material.mainTexture](/engine/6000.7/script-reference/unityengine/material/maintexture.md) property.

`"_BumpMap"` is the normal map.

The shader properties also show some of the keywords needed to set the Texture of a Material. To see this, go to your Material and right click on the **Shader** dropdown at the top. Next, pick **Select Shader**.

By specifying a `RenderTextureSubElement`, you can indicate which type of data to set from the RenderTexture. The possible options are: [RenderTextureSubElement.Color](/engine/6000.7/script-reference/unityengine/rendering/rendertexturesubelement/color.md), [RenderTextureSubElement.Depth](/engine/6000.7/script-reference/unityengine/rendering/rendertexturesubelement/depth.md), and [RenderTextureSubElement.Stencil](/engine/6000.7/script-reference/unityengine/rendering/rendertexturesubelement/stencil.md).

Additional Resources: [Material.mainTexture](/engine/6000.7/script-reference/unityengine/material/maintexture.md) property, [Material.GetTexture](/engine/6000.7/script-reference/unityengine/material/gettexture.md), [Shader.PropertyToID](/engine/6000.7/script-reference/unityengine/shader/propertytoid.md), [Properties in Shader Programs](/engine/6000.7/manual/materials-and-shaders/shaders/writing-custom/shader-writing/writing-shader-change-properties/sl-properties-in-programs.md), [RenderTextureSubElement](/engine/6000.7/script-reference/unityengine/rendering/rendertexturesubelement.md).

### Examples

```csharp
//Attach this script to your GameObject (make sure it has a Renderer component)
//Click on the GameObject. Attach your own Textures in the GameObject’s Inspector.

//This script takes your GameObject’s material and changes its Normal Map, Albedo, and Metallic properties to the Textures you attach in the GameObject’s Inspector. This happens when you enter Play Mode

using UnityEngine;

public class Example : MonoBehaviour {

    //Set these Textures in the Inspector
    public Texture m_MainTexture, m_Normal, m_Metal;
    Renderer m_Renderer;

    // Use this for initialization
    void Start () {
        //Fetch the Renderer from the GameObject
        m_Renderer = GetComponent<Renderer> ();

        //Make sure to enable the Keywords
        m_Renderer.material.EnableKeyword ("_NORMALMAP");
        m_Renderer.material.EnableKeyword ("_METALLICGLOSSMAP");

        //Set the Texture you assign in the Inspector as the main texture (Or Albedo)
        m_Renderer.material.SetTexture("_MainTex", m_MainTexture);
        //Set the Normal map using the Texture you assign in the Inspector
        m_Renderer.material.SetTexture("_BumpMap", m_Normal);
        //Set the Metallic Texture as a Texture you assign in the Inspector
        m_Renderer.material.SetTexture ("_MetallicGlossMap", m_Metal);
    }
}
```
