# SetMaterial

> Set the material for the canvas renderer. If a texture is specified then it will be used as the 'MainTex' instead of the material's 'MainTex'. Additional Resources: CanvasRenderer.materialCount, CanvasRenderer.SetTexture.

## Definition

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

## SetMaterial(Material, int)

Set the material for the canvas renderer. If a texture is specified then it will be used as the 'MainTex' instead of the material's 'MainTex'. Additional Resources: [CanvasRenderer.materialCount](/engine/6000.0/script-reference/unityengine/canvasrenderer/materialcount.md), [CanvasRenderer.SetTexture](/engine/6000.0/script-reference/unityengine/canvasrenderer/settexture.md).

```csharp
public void SetMaterial(Material material, int index)
```

### Parameters

**** (\[Material]\(/engine/6000.0/script-reference/unityengine/material)): Material for rendering.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): Material index.

## SetMaterial(Material, Texture)

Set the material for the canvas renderer. If a texture is specified then it will be used as the 'MainTex' instead of the material's 'MainTex'. Additional Resources: [CanvasRenderer.materialCount](/engine/6000.0/script-reference/unityengine/canvasrenderer/materialcount.md), [CanvasRenderer.SetTexture](/engine/6000.0/script-reference/unityengine/canvasrenderer/settexture.md).

```csharp
public void SetMaterial(Material material, Texture texture)
```

### Parameters

**** (\[Material]\(/engine/6000.0/script-reference/unityengine/material)): Material for rendering.**** (\[Texture]\(/engine/6000.0/script-reference/unityengine/texture)): Material texture overide.
