Material will only update when selected in Hieracy

I’m using the Standard (specular setup) shader, assigning Albedo, Spec and Normal maps at runtime.
The material only updates when i click on it in the hierachy? (Doesnt update at all in a Build)
I have tried using the Shader.EnableKeyword but it didnt make a difference.
Any suggestions??
Thanks

When procedurally creating a Standard shader based material, you need to make sure you’re also pairing those assigned maps with the setup the Standard shader expects to correctly use them.

The easiest way to see exactly what’s required for each feature is to read through the custom editor used for the Standard shader StandardShaderGUI.cs and replicate that in your own code. You can acquire this file by downloading the builting_shader.zip matching your Unity version from here: Download Archive.

Specifically for the example you gave above… if you’re setting up your material roughly as this:

var procMat = new Material(Shader.Find("Standard (Specular setup)"));
procMat.SetTexture("_MainTex", myAlbedo);
procMat.SetTexture("_BumpMap", myNormal);
procMat.SetTexture("_SpecGlossMap", mySpecGloss);

Then at the very least you need to match that with:

procMat.EnableKeyword("_NORMALMAP");
procMat.EnableKeyword("_SPECGLOSSMAP");

Another thing to keep in mind is that you also need to make sure that the shader variants you wish to use are actually included in your standalone build. Shader variants created using #pragma shader_feature (which includes normal map and specgloss map support) are only included in standalone builds if they are actually referenced by a material, so you might have to throw in some proxy objects to make sure the desired shader variants get included in the build. (another option would be to always include the standard shader, but I wouldn’t really recommend that as it has a ridiculous amount of variants that will bloat your exe and build times)

1 Like