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:
i.e.

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 = myBaseMaterial.name;
String assignedMaterialName = myRenderer.sharedMaterial.name;

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

Comparing sharedMaterial works for me.

Example:

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

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