_SPECULARHIGHLIGHTS_OFF in final build

Hello everyone, this is my situation: I create a plane game object at runtime and then set up its material, something like this:

GameObject canvas = GameObject.CreatePrimitive(PrimitiveType.Plane);
...
Renderer renderer = canvas.GetComponent<Renderer>();
renderer.material.SetTexture("_MainTex", MyTexture);
renderer.material.EnableKeyword("_NORMALMAP");
renderer.material.SetTexture("_BumpMap", MyNormalMap);
renderer.material.EnableKeyword("_SPECULARHIGHLIGHTS_OFF");

This works when I debug my program in the editor, problem comes when I do the final build - I just can’t get “_SPECULARHIGHLIGHTS_OFF” to have an effect.

In the docs it says, “Use shader variant collections to prewarm shader variants, or to ensure that shader variants that are required at runtime but not referenced in a scene are not excluded (“stripped”) from your build.” So I created a shader variant collection and put it in my Resources folder. Then, in the inspector I added the Standard shader and clicked the “+” to open the “Add shader Standard variants to collection” menu. Here I selected my keywords “_NORMALMAP” and “_SPECULARHIGHLIGHTS_OFF” and clicked one of the shaders in the “Shader variants with these keywords (click to select):” list.

This way my normal map works in the final build, however specular highlights are still on.

Also: Is there a better way of creating the shader variant collection? In the docs it also says: “The Unity Editor can track which shader variants your application uses when it runs, and automatically create a shader variant collection asset that contains them.” However, when I export this shader variant collection and put it in my Resources folder, not even the normal maps work in the final build.

Help would be much appreciated

Is there really no one having a solution for this issue?

You can enable “strict variant matching” and check the player logs to see which variant it actually tries to use.

1 Like

Thanks for your help! It turns out “strict variant matching” is only available in Unity 2022 - before I was using 2021.3.3f1. Funny thing is, if I manually create the shader variant collection in 2022.3.3f1, specular lights are off in the final build. Automatically generating the shader variant collection still doesn’t work, but having the other solution is good enough for me right now