Normal map not rendered until the material asset is selected in the inspector

  1. I apply a material to an object. (click and drag, or in renderer component)
  2. The material applies mostly correct, but renders without Normal map
  3. I click the material in the asset window, aka select it in the inspector
  4. Normal map suddenly works and is rendering properly

I have an Editor Script that creates Material assets using the Standard shader. And as described above, I have to click/select each material individually in the asset window else the Normal texture is ignored. This somewhat defeats the purpose of automating the process…

Anyone have an idea on how I can fix this? AssetDatabase.refresh() doesn’t help, surely there’s some way script-wise to deal with it. Please and thank you!

The script in question.

Hello @colin_windmuller

Regardless of creating a material on runtime or in editor, you have to activate the keyword related to the texture you are using. In your case you need to call

myMaterial.EnableKeyword("_NORMALMAP");

before assigning your texture. By default, since no normal map, occlusion map etc. is used in the newly created material, this keyword will be inactive unless you click on editor which causes an update on it.

You can find more about the keywords in here

And about general info on shader variants here

Hope this helps.