# 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'.

## Definition

* **Type:** Method
* **Namespace:** [UnityEngine](/engine/6000.7/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'.

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

### Parameters

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

### Remarks

Additional Resources: [\_materialCount](/engine/6000.7/script-reference/unityengine/canvasrenderer/materialcount.md), [CanvasRenderer.SetTexture](/engine/6000.7/script-reference/unityengine/canvasrenderer/settexture.md)

## 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'.

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

### Parameters

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

### Remarks

Additional Resources: [\_materialCount](/engine/6000.7/script-reference/unityengine/canvasrenderer/materialcount.md), [CanvasRenderer.SetTexture](/engine/6000.7/script-reference/unityengine/canvasrenderer/settexture.md)
