# Material Changer

## Overview

Allows to change materials on a mesh or meshes on a same gameObject

![](/files/-M4elAJM-Isu4th4mxwJ)

It uses a List of **<**[**Material Items**](/animal-controller/utilities/material-changer.md#material-item)**>** to set 1 or more material changes to 1 or more meshes at the same time.

You can create any new [**Material Item**](/animal-controller/utilities/material-changer.md#material-item) by clicking on the Plus(**+**) button of the list.

![](/files/-M4em0XhvKZTdGvIGbX_)

## Properties

### Show/Hide Properties <img src="/files/-M4emTCHdixGwu5myJXZ" alt="" data-size="original">&#x20;

Shows/Hide the selected  [**Material Item**](/animal-controller/utilities/material-changer.md#material-item) properties.

![](/files/-M4emjsKl9ZlbKzTf9CY)

When you select a [**Material Item**](/animal-controller/utilities/material-changer.md#material-item) on the list you will have the (Index), the Name, and Button with the Current Material used on the Mesh of that Material Item

![](/files/-M4epF3rlGyk6GaPX9er)

### Change Hide Meshes \[CH]

It will change the material even if the Mesh renderer is Hidden

### Random \[R]

It will set a random Material on Start on every [**Material Item**](/animal-controller/utilities/material-changer.md#material-item). Useful to create random variations

### Change Material Button

{% hint style="info" %}
When you click the Change Material Button it will cycle between all the [Materials ](/animal-controller/utilities/material-changer.md#material-list)on the Material Item.**This only work on the Editor.** For Game purposes use [Public methods](/animal-controller/utilities/material-changer.md#public-methods).
{% endhint %}

![](/files/-M4enDeQoKDgogjfX6k7)

## Material Item

The Material Item is a struct class that holds all the Parameters and properties needed to change the material on a single mesh and its LODs

![](/files/-M4epa0953-kJbniuavb)

### Mesh

Mesh Renderer used to change the materials.

### ID

Sometimes a Mesh can have multiple materials assigned. They can me Identified by a Material ID

![Unka the Dragon is a single mesh with multiple Materials](/files/-M4erXN_6fnnK7keFSp2)

![Unka has the same mesh on 2 Material Items. ID is 0 for the \[Skin\] and 1 for \[Wings\] ](/files/-M4ertRB0bon_KKNhiYI)

### Material List

All the Materials a single mesh can cycle trough.&#x20;

### LODs

If a Mesh has LODs you set them here. It will change the same material to multiple to the meshes on the LOD List.

![](/files/-M4et8vNOU0wULiDdjK7)

### Linked Master  <img src="/files/-M4eurVZh1PfSB9jEanv" alt="" data-size="original">&#x20;

When enabled, a material Item will be Locked and it will only change if the Master Material Item change. The Master property is the Index of the Material Item.

*E.g. On the Elemental Dragon the Wings will change automatically to another material when the Body Material Changes*

![](/files/-M4evWQQEtcLKNCgKlQ6)

### On Material Changed Event

Is invoked when a Material Item changes a material

## Public Methods

### `void Randomize()`

> Randomize all the Material Items on the Material Changer Component

### `void SetMaterial(int index, bool next = true)`

> Changed to the Next/Before Material on the Material Item using its Index on the List
>
> **index** - Material Item Index on the list
>
> **next** - if **True** it will change to the next material, if **False** it will change to the last material

### `void SetMaterial(string name, int index)`

> Changed to the Material on the Material Item using its name and the material Index
>
> **name:** Material Item name
>
> **index:** index of the Material inside the Material Item

### `void SetMaterial(string name, bool next = true)`

> Changed to the Next/Before Material on the Material Item using its name
>
> **`name`**  Material Item name
>
> **`next`** if **True** it will change to the next material, if **False** it will change to the last material

### `void SetMaterial(int index, int nextIndex)`

> Changed to a specific Material on the Material Item using its Index on the List.&#x20;
>
> **`index`** Material Item Index on the List
>
> **`nextIndex`**&#x4D;aterial Index on the Material Item

### `void NextMaterialItem(int index)`

> Changed to the next Material on the Material Item using its Index on the List.&#x20;
>
> **`index`** Material Item Index on the List

### `void NextMaterialItem(int index)`

> Changed to the next Material on the Material Item using its Index on the List.&#x20;
>
> **`index`**&#x4D;aterial Item Index on the List

### `void NextMaterialItem(string name)`

> Changed to the next Material on the Material Item using its Index on the List.&#x20;
>
> **`name`**&#x4D;aterial Item name on the List

### `int CurrentMaterialIndex(string name)`

> Returns the Current Index of a Material used on a Material Item&#x20;
>
> **`name`**&#x4D;aterial Item name on the List


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://malbersanimations.gitbook.io/animal-controller/utilities/material-changer.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
