Difference Between Material and Shared Material: Unity Tutorial

In this article, we will see the difference between material and shared material property of renderer component for unity applications.

Material

Material property provides you the cloned instance of the material referenced to the renderer of the GameObject. Any change in the material property will reflect only on the referenced GameObject.

Get material property of the Meshrenderer Component.

It will print the cloned instance of the base material applied to the GameObject.

Material Result

Shared Material

SharedMaterial property provides you the actual material referenced to the renderer of the GameObject.  Any change in the shared material will reflect to all of the referenced GameObejct.

Get sharedMaterial property of the Meshrenderer Component.

It will return the actual material assigned to the GameObject.

Shared Material Result

Now, we will see the the difference between the material and shared material using a simple example.

Example:

Let’s prepare a simple scene which is having two sphere GameObjects only . Then create a new material (Assets -> Create -> Material) and assign this material to both of the Sphere GameObject. Now, both of these GameObjects have the same material asset assigned.

Example Scene - Material and Shared Material

Create a New Script (Assets -> Create -> C# Script) and attach it to the Main Camera GameObject. In the script, both of the GameObject is referenced to the same material asset. When we will change the sharedMaterial of one GameObject then it will also reflect on the other GameObject.

Initialize the public variables of the script in the unity editor.

Run the application and color at runtime.

Now change the material property instead of sharedMaterial.

Hope, you get an idea about material and shared material of a GameObject. Please post your comment for queries and feedback. Thanks for reading.

Share Button
The following two tabs change content below.
Gyanendu Shekhar is a technology enthusiast. He loves to learn new technologies. His area of interest includes Microsoft technologies, Augmented reality, Virtual reality, unity3d and android development.

Gyanendu Shekhar

Gyanendu Shekhar is a technology enthusiast. He loves to learn new technologies. His area of interest includes Microsoft technologies, Augmented reality, Virtual reality, unity3d and android development.

Leave a Reply

Your email address will not be published. Required fields are marked *