Hi all,
I’m using an Editor script to automatically apply Smoothness and Metallic properties to Materials with certain names, whenever an FBX is updated.
I recently learned that even though I set the smoothness/metallic values via script, in order to see those Material changes reflected in the Scene after the FBX is imported, I had to use:
mat.EnableKeyword("_METALLICGLOSSMAP");
Enabling this, however results in something weird. The Materials that got the correct Smoothness, now visually have Metallic stuck at 1 (so, fully metallic) when looking at the scene.
It seems to be a refresh problem, because if I go select the Material in the inspector, the Material in the scene suddenly updates to the correct graphical representation and loses its metallic look, and the Metallic slider reveals the correct value. I can move it back to 1.0 and reproduce how the scene looked before, right after the script is run.
Here’s the code I’m using:
Material mat = (Material)AssetDatabase.LoadAssetAtPath(materialFilePath, typeof(Material));
mat.EnableKeyword("_NORMALMAP");
mat.EnableKeyword("_METALLICGLOSSMAP");
// set its smoothness channel to albedo
mat.SetInt("_SmoothnessTextureChannel", 1);
// set it to the given smoothness (glossiness) value
mat.SetFloat("_GlossMapScale", smoothness);
Even if I add:
mat.SetFloat("_Metallic", 0);
… when the script runs, the Material still appears in the scene as if it has a Metallic value of 1. And again, clicking on the Material thumbnail to bring up the inspector fixes it until the next time the asset is updated, but I can’t be doing this for all my Materials, manually.
I’ve verified this behavior on 2019.1.6f1 and 2019.2.0b7.
Am I missing another Keyword? I’ve tried everything I see in the shader, to no avail. Other ideas?
Thanks in advance.