How to compare 2 materials?

Similar questions have been asked but none of those solutions seems to work for me.

I want to compare 2 materials to see if they are the same:

if(material1 == object.renderer.sharedMaterials[0])
 Debug.Log("Great success!");

But this compares false even when I know it to be true. Outputting the name of the shared material shows that it is an instance of the material. How can I get the original in order to compare them?

You could compare by name:

Given you have a material in your project called “MyMaterial” it might be on your actual gameObject a “MyMaterial (Instance)”. Because you assigned other textures, colors or so.

Now do something like this:
String baseMaterialName =;
String assignedMaterialName =;

if (assignedMaterialName.Contains(baseMaterialName) ) {
// here is your Match

Comparing sharedMaterial works for me.


Debug.Log(GameObject.Find(“obj1”).GetComponent().sharedMaterial == GameObject.Find(“obj2”).GetComponent().sharedMaterial)

=> returns “False” even if the material names are the same