With how calling renderer.material creates a new instances of a material, this has caused me countless grief in Unity. I have spent countless hours trying to track down and figure out why a new material instance is being created, and thus static batching breaks.
renderer.material = some material //OK
Debug.Log(renderer.material.name); //Doing this creates a brand new material
Simply doing the Debug.Log causes Unity to create a brand new material. Now, the material the renderer is using is not the same as the material that was assigned to on the first line.
I don’t know if this is some design flaw with Unity but I don’t know how to prevent myself for continuing to make this “mistake”.
Anyone else here continues to do this?