# Material Changer

## Overview

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

![](https://963537199-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lzhr1XSMzMqNXjRnNlb%2F-M4ej0E-T49bMunTxW6j%2F-M4elAJM-Isu4th4mxwJ%2Fimage.png?alt=media\&token=ef17a031-854a-4cfd-b38d-d2ea73fbb4e4)

It uses a List of **<**[**Material Items**](#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**](#material-item) by clicking on the Plus(**+**) button of the list.

![](https://963537199-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lzhr1XSMzMqNXjRnNlb%2F-M4ej0E-T49bMunTxW6j%2F-M4em0XhvKZTdGvIGbX_%2Fh7Qc5i0PUx.gif?alt=media\&token=2bb2b99c-729b-4a14-97c1-337b39b9bed5)

## Properties

### Show/Hide Properties <img src="https://963537199-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lzhr1XSMzMqNXjRnNlb%2F-M4ej0E-T49bMunTxW6j%2F-M4emTCHdixGwu5myJXZ%2FUnity_DCTaiu9XVq.png?alt=media&#x26;token=d8d5e1b4-e78d-4e46-9225-d1b8329bb4ba" alt="" data-size="original">&#x20;

Shows/Hide the selected  [**Material Item**](#material-item) properties.

![](https://963537199-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lzhr1XSMzMqNXjRnNlb%2F-M4ej0E-T49bMunTxW6j%2F-M4emjsKl9ZlbKzTf9CY%2FegFRtblJdm.gif?alt=media\&token=19cd53af-9a4f-4c28-91d6-263e13ca585d)

When you select a [**Material Item**](#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

![](https://963537199-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lzhr1XSMzMqNXjRnNlb%2F-M4ej0E-T49bMunTxW6j%2F-M4epF3rlGyk6GaPX9er%2Fimage.png?alt=media\&token=c24bb838-6d94-4fb0-9d74-5d55a321ad42)

### 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**](#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 ](#material-list)on the Material Item.**This only work on the Editor.** For Game purposes use [Public methods](#public-methods).
{% endhint %}

![](https://963537199-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lzhr1XSMzMqNXjRnNlb%2F-M4ej0E-T49bMunTxW6j%2F-M4enDeQoKDgogjfX6k7%2FGckLjIXW7s.gif?alt=media\&token=44c74385-061f-4a81-8e21-070b96ce3d21)

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

![](https://963537199-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lzhr1XSMzMqNXjRnNlb%2F-M4ej0E-T49bMunTxW6j%2F-M4epa0953-kJbniuavb%2Fimage.png?alt=media\&token=596f7216-f41b-4a8c-9845-fea78d4b5e3b)

### 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](https://963537199-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lzhr1XSMzMqNXjRnNlb%2F-M4epwNenwMzclFYqnsK%2F-M4erXN_6fnnK7keFSp2%2Fimage.png?alt=media\&token=73c55b46-7b35-4d7a-8545-794e1b8c5f6e)

![Unka has the same mesh on 2 Material Items. ID is 0 for the \[Skin\] and 1 for \[Wings\] ](https://963537199-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lzhr1XSMzMqNXjRnNlb%2F-M4epwNenwMzclFYqnsK%2F-M4ertRB0bon_KKNhiYI%2FeGsUtbZsDy.gif?alt=media\&token=6960fc23-4d9f-449b-a588-19e84f2b7c2a)

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

![](https://963537199-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lzhr1XSMzMqNXjRnNlb%2F-M4epwNenwMzclFYqnsK%2F-M4et8vNOU0wULiDdjK7%2Fimage.png?alt=media\&token=0887063d-4c1d-4392-8d5b-95ada8d5e2f3)

### Linked Master  <img src="https://963537199-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lzhr1XSMzMqNXjRnNlb%2F-M4euNW2BY_10_3xbGgf%2F-M4eurVZh1PfSB9jEanv%2FUnity_XBoo5BNdN6.png?alt=media&#x26;token=90e2fd80-6bc9-46ff-b8a7-026b0bbf05ee" 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*

![](https://963537199-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lzhr1XSMzMqNXjRnNlb%2F-M4euNW2BY_10_3xbGgf%2F-M4evWQQEtcLKNCgKlQ6%2FG4FCcJOPR5.gif?alt=media\&token=23985fc1-3b41-47d7-8e64-64ab98a0234c)

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