Assigning a sharedMaterial to multiple renderers that change together
I searched around but no one seemed to have the problems I'm having.
First off I have a car and I want to change the paint but all the materials are instances so I decided to instead assign all the materials to a common sharedMaterial, however nothing I do seems to be working.
I tried creating a material instance and assigning it to all the renderers.
Material newMat = currentCar.GetComponent<GameState>().notSharedMaterial;
foreach (Transform child in currentCar.GetComponent<GameState>().frontBumpers.transform) {
child.GetComponent<Renderer>().sharedMaterial=newMat;
}
I tried getting the sharedMaterial from the first instance and assigning it to the cars renderers
Material newMat = currentCar.GetComponent<GameState>().notSharedMaterial;
frontBumpers[0].GetComponent<Renderer>().sharedMaterial=newMat;
foreach (Transform child in currentCar.GetComponent<GameState>().frontBumpers.transform) {
child.GetComponent<Renderer>().sharedMaterial=frontBumpers[0].GetComponent<Renderer>().sharedMaterial;
}
but no matter what I do, all the paintable parts on the car are material instances instead of the original material referenced. Is there something I'm doing wrong here? I've switched out material,sharedMaterial,created new materials and nothing I'm doing is working. Any help?
UPDATE: I tried this EXACT method with simple spheres and it worked!??? BUT this doesn't work with my car?
Spheres: get changed no problem. Car: creates instances on EVERYTHING and doesn't do what it was intended?
Hi, it seems I have a similar problem. I Instantiate a prefab that creates an instance of the used material, that still share the same source material but is not modified by shared$$anonymous$$aterial. Is it the same here? I tried to reaffect the source material by code after instantiation but it still is an instanced material. I use Unity 5.2.0f3 personal 32 bit edition.
Did you find a solution? Thanks.