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?

Use “sharedMaterial” property instead of “material”. Also I dunno if it’s gonna fit in your situation.

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.

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: