Specular Material Not Updating, but Standard is ok?
I am creating and assigning materials dynamically in my pipeline. This works well for all use with the Standard Unity shader. However, when I use the "Standard (Specular Setup)" shader, then the material is all black until I select the material in some way so it's displayed in the inspector.
Now, this question has been asked a couple of times and the answer is to make sure that the material has the correct keywords enabled. Well, I do that. In the case of the specular setup, it's going to have:
mat.EnableKeyword("_SPECGLOSSMAP");
mat.EnableKeyword("_NORMALMAP");
So, unless this shader is different than the "Standard" one, then I don't think they way I'm constructing the material is a problem.
I'm guessing the issue is something with it not being referenced or a loaded resource until it's selected.
Perhaps something in my assignment code? That looks like this:
Object[] matchingModels = Resources.FindObjectsOfTypeAll(typeof(GameObject)).Where(a => a.name.Equals(meshName)).ToArray();
foreach (var model in matchingModels)
{
GameObject gameModel = (GameObject)model;
if (gameModel != null)
{
Renderer r = gameModel.GetComponent<Renderer>();
if (r != null)
{
r.sharedMaterial = myCreatedMaterial;
}
}
}
I'm not quite sure what else to try. Any suggestions?
Answer by dmm_jbw · Apr 20, 2016 at 11:51 PM
For anyone looking for the answer, keywords were STILL the problem and answer.
I was specifying mat.EnableKeyword("_SPECGLOSSMAP") even in the case where I was only looking for specular colour. By enabling the keyword, but NOT setting a texture to _SpecGlossMap it caused it to appear black.
Selecting the material in the inspector must have brought some sanity here and cleared the keyword.
Hello. Thanks you for the answer on own question.
Today I encountered with the same problem, decided to check Unity Answers by entering "_SpecGloss$$anonymous$$ap" and seems like you saved my nerves and time and I have avoided a lot of thinking about "Why it does not works?!" : )
Thanks.