Hey there, I’ve been struggling with what seems to be a simple problem, and I’m hoping the answer is just as simple.
I’ve been working on a tool to merge texture sets and automatically create a new material asset for those texture sets, and everything works so far, aside from the metallic smoothness channel. After looking around yesterday, I read that you need to use EnableKeyword to indicate shader variants.
I’ve broken down a small part of my code to give an overvierw:
Texture2D MetallicGlossMap = (Texture2D)AssetDatabase.LoadAssetAtPath("/PathOf/RecentlySavedPNGAsset.png", typeof(Texture2D));
Material newMaterial = new Material(Shader.Find("Standard"));
// Enable the reqired Shader Variants
newMaterial.EnableKeyword ("_METALLICGLOSSMAP");
newMaterial.EnableKeyword ("_NORMALMAP");
newMaterial.EnableKeyword ("_DETAIL_MULX2");
newMaterial.EnableKeyword ("_PARALLAXMAP");
newMaterial.SetTexture ("_MetallicGlossMap",MetallicGlossMap);
// And obviously the other required Textures.
//newMaterial.SetTexture ("_BumpMap",..Normal Map...);
//newMaterial.SetTexture ("_EmissionMap",...Emission Map...);
AssetDatabase.CreateAsset (newMaterial,"/PathOfTheMaterial.mat");
AssetDatabase.ImportAsset("/PathOfTheMaterial.mat", ImportAssetOptions.ForceUpdate);
The result is a newly created .mat file with every channel I’ve needed so far, with exception of metallic smoothness. on first Inspection using debug mode, I do see the shader keywords applied as I’ve illustrated in the screenshot attached, however, when I use the normal inspector and return to debug inspector, those keywords have been removed.
If anyone has any pointers as to what I am doing wrong, I’d really appreciate it.
