Search Unity

Material will only update when selected in Hieracy

Discussion in 'General Graphics' started by hersheys72, Jan 12, 2017.

  1. hersheys72

    hersheys72

    Joined:
    Sep 4, 2015
    Posts:
    7
    I'm using the Standard (specular setup) shader, assigning Albedo, Spec and Normal maps at runtime.
    The material only updates when i click on it in the hierachy? (Doesnt update at all in a Build)
    I have tried using the Shader.EnableKeyword but it didnt make a difference.
    Any suggestions??
    Thanks
     
    Last edited: Jan 12, 2017
  2. shaggydogstudios

    shaggydogstudios

    Joined:
    Dec 26, 2013
    Posts:
    10
    When procedurally creating a Standard shader based material, you need to make sure you're also pairing those assigned maps with the setup the Standard shader expects to correctly use them.

    The easiest way to see exactly what's required for each feature is to read through the custom editor used for the Standard shader StandardShaderGUI.cs and replicate that in your own code. You can acquire this file by downloading the builting_shader.zip matching your Unity version from here: https://unity3d.com/get-unity/download/archive.

    Specifically for the example you gave above.. if you're setting up your material roughly as this:
    Code (csharp):
    1. var procMat = new Material(Shader.Find("Standard (Specular setup)"));
    2. procMat.SetTexture("_MainTex", myAlbedo);
    3. procMat.SetTexture("_BumpMap", myNormal);
    4. procMat.SetTexture("_SpecGlossMap", mySpecGloss);
    Then at the very least you need to match that with:
    Code (csharp):
    1. procMat.EnableKeyword("_NORMALMAP");
    2. procMat.EnableKeyword("_SPECGLOSSMAP");
    Another thing to keep in mind is that you also need to make sure that the shader variants you wish to use are actually included in your standalone build. Shader variants created using #pragma shader_feature (which includes normal map and specgloss map support) are only included in standalone builds if they are actually referenced by a material, so you might have to throw in some proxy objects to make sure the desired shader variants get included in the build. (another option would be to always include the standard shader, but I wouldn't really recommend that as it has a ridiculous amount of variants that will bloat your exe and build times)
     
    FlashMuller likes this.