SetTexture Not Working In Unity 5

Unity Version (5.1.1f1)

I’m currently using the Standard Shader when creating Materials dynamically through script at runtime. When apply a texture using the method below, I’m able to see my Diffuse Texture:

SetTexture("_MainTex", myDiffTex);

However, after attempting to apply my next 2 textures, they never get updated in the viewport:

SetTexture("_MetallicGlossMap", mySpecTex);
SetTexture("_BumpMap", myBumpTex);

However, once I go over to the inspector and select the dropdown for the material, everything updates and my changes are reflected in the main view. (I’ve attached images demonstrating this)

Is this a bug in Unity 5?


Ok so it appears the problem was with this new thing called ‘EnableKeyword’.

Because of the new nature of the Standard Sharder and how variants work, you have to actually enable the keywords that you are looking to apply to this shader.

Doing this fixed it for me:

// For '_BumpMap'
material.EnableKeyword("_NORMALMAP");

// For '_MetallicGlossMap'
material.EnableKeyword("_METALLICGLOSSMAP");

I don’t know why,but after i invoke SetTexture twice the problem is solved and the texture of material is updated