Material.Setfloat not working properly in Editor, is that a bug?

Hi all,

After I upgrade all my materials to the HDRP materials, the alpha clipping is turned off. I’m writing an editor script that can turn on alpha clipping for all transparent unlit materials.

Here is my code:

    public static void FixAlphaClipping(Material mat)
    {
        var shaderName = mat.shader.name;
        Debug.Log(shaderName);
        Debug.Log(mat.GetFloat("_AlphaCutoffEnable"));
        if (mat.shader.name == "HDRP/Unlit")
        {
            if (mat.GetFloat("_SurfaceType")==1f)
            {
                Debug.Log("Surface Type Transparent");
                mat.SetFloat("_AlphaCutoffEnable",1f);
                //mat.set("_SurfaceType",0);
            }
            else
            {
                Debug.Log("Surface Type Opaque");
            }
           
        }
    }

The code works fine. I can see the “Alpha Clipping” is turned on in the inspector. However, nothing happened in the scene view.
The funny thing is if I modify something completely irrelevant in the inspector, surface color, for example, the setting will apply.

Is this a bug?

Mystery Solved!

1 Like