I have a fairly simple question: I am trying to change an object’s material via code with the line
rend.material = NewMat;
where rend
is of type Renderer
(MeshRenderer
to be specific) and NewMat
is of type Material
. Both variables are public and assigned in the inspector and both are not null.
When I now try to assign the material, nothing happens. I don’t event get any error. When I look into the inspector I can see that under Materials on my MeshRenderer the material doesn’t even change. The line
Debug.Log(rend.material == NewMat);
outputs false
.
What am I doing wrong?,I have a fairly simple question: I am trying to change an object’s material via code with the line
rend.material = NewMat;
where rend
is of type Renderer
(MeshRenderer
to be specific) and NewMat
is of type Material
. Both variables are public variables with values assigned in the inspector and both are not null
.
When I now try to assign the material, nothing happens. I don’t event get any error. When I look into the inspector I can see that under Materials
on my MeshRenderer
the material doesn’t even change. The line Debug.Log(rend.material == NewMat);
outputs false
.
What am I doing wrong?