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:


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?

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.