I am trying to lookup materials by name and set a texture. My first attempt was
if(renderer.material.name == "My Material")
renderer.material.SetTexture(newTex);
… then I noticed the " (Instance)" attached to the material’s name (e.g. renderer.material.name == “My Material (Instance)”). So my second attempt was
if(renderer.sharedMaterial.name == "My Material")
renderer.material.SetTexture(newTex);
… this works… the first time.
Unfortunately the second time I call my function I noticed that the renderer.sharedMaterial’s name is now equal to “My Material (Instance)”. In other words, after any call to renderer.material the renderer.material == renderer.sharedMaterial.
Can somebody explain this? Once I access renderer.material how can I access the original renderer.sharedMaterial? Shouldn’t sharedMaterial always point to the original shared material?