Hi there
I’ve got a system that needs to modify a material on an object that has a number of materials applied. From what I can gather, getting the materials via MeshRenderer.materials creates new instances of every one of those materials. Since I only ever want to modify one of the materials and I would prefer to keep the other shared materials intact, is there a way to do this for only one item of the array? Would I have to do something really hacky like
var materials = m_MeshRenderer.materials;
var sharedMaterials = m_MeshRenderer.sharedMaterials;
for (int i = 0; i < materials.Length; ++i)
{
if (i != indexToKeep)
{
Destroy(materials[i]);
materials[i] = sharedMaterials[i];
}
}
m_MeshRenderer.materials = materials;
Or is it really not worth worrying about?
Thanks