Why is my material not changing?
I've got a piece of code that simply changes the material of an object, but it doesn't seem to want to work. In both the debugger and the Unity inspector, it shows that there is a change, but in the game it shows the old material.
Code snippet below:
gameObject.GetComponent<Renderer>().material = faceData.FacesMaterial;
What am I doing wrong here?
I'd guess it is working (if you can see it change,) but something else is stomping on it (duplicate object at same spot with old material ... .) Usually playing around more in Pause can find it (for example, manually switching $$anonymous$$ats.)
Answer by Nosrick · Mar 20, 2015 at 11:30 PM
I found the problem: my prefab has a child called pCube, and is a model with a shader attached to it, which in turn has the first material on it. The prefab itself also has a material on it, which will not override pCube's material. It turns out it's the model's fault.
Normally I'd delete this question now, but I'll leave it up in case others have the same problem.
Can you please go in to more detail on how you fixed the problem? I have the same issue but i cant figure out how to fix it based on this answer.
Answer by Utamaru · Mar 20, 2015 at 04:40 PM
Use "sharedMaterial" property instead of "material". Also I dunno if it's gonna fit in your situation.
Answer by The_MAnimal · Nov 10, 2018 at 09:28 PM
I have experienced this issue with object imported from Blender, for me helped to change rollup window in Material setings from "Standart" to "Standart (Specular setup)"
I did import of blender object like is in video: https://youtu.be/konL0iB5gPI?t=56