Loading normal and specular maps in runtime Problem

Hi!

I’m kinda lost in this thing of loading a diffuse/normal and specular maps in runtime (C#). These maps are created on the fly so to load them I just do

Renderer rend = GetComponent<Renderer> ();
rend.material.mainTexture =  newDiffuse;
rend.material.SetTexture ("_BumpMap", newNormal);
rend.material.SetTexture ("_MetallicGlossMap", newSpecular);

The thing is that only the diffuse map is actually loaded well. The other two only affect the model when I pause the execution and press on the standard shader component on the inspector… :/… This is probably a noob question, but I can’t seem to figure out the answer. Please help!
Thanks!

Could it be because of how the shaders are created specifically to what parameters are under use? If those two textures are not used when you enter play mode, the material may be using a shader variation that does not have them, Pausing execution and focusing on the inspector may be causing it to rebuild, only this time the values are set so it builds the appropriate shader variation.

Try putting placeholder textures into those fields for the shader before you enter play mode (I’d suggest low resolution neutral maps, so a flat normal map etc).

I might be way off, but it’s just a thought.

Found the answer… →

But in a nutshell, some parts of the shader are not activated if not used… so I needed to put
material.EnableKeyword(“_NORMALMAP”); in any map to force the shader to use the new map info… :confused: