Search Unity

Question Setting Enum Property via Code Not Working in Build

Discussion in 'Shader Graph' started by JudahMantell, Sep 16, 2022.

  1. JudahMantell

    JudahMantell

    Joined:
    Feb 28, 2017
    Posts:
    476
    I'm working on a URP Project and I'm using an enum property to allow for different "modes" of my shader. It works well in the editor, and I am able to switch between the values in c# using this function:

    Code (CSharp):
    1.  public static void SetViewMode(Material m, int mode)
    2.         {
    3.             m.DisableKeyword("_VIEWMODE_FINALOUTPUT");
    4.             m.DisableKeyword("_VIEWMODE_SOURCE");
    5.             m.DisableKeyword("_VIEWMODE_KEY");
    6.             m.DisableKeyword("_VIEWMODE_LUMA");
    7.             m.DisableKeyword("_VIEWMODE_ALPHA");
    8.             m.DisableKeyword("_VIEWMODE_DESPILL");
    9.  
    10.             switch (mode)
    11.             {
    12.                 case 0:
    13.                     m.EnableKeyword("_VIEWMODE_FINALOUTPUT");
    14.                     break;
    15.                 case 1:
    16.                     m.EnableKeyword("_VIEWMODE_SOURCE");
    17.                     break;
    18.                 case 2:
    19.                     m.EnableKeyword("_VIEWMODE_KEY");
    20.                     break;
    21.                 case 3:
    22.                     m.EnableKeyword("_VIEWMODE_LUMA");
    23.                     break;
    24.                 case 4:
    25.                     m.EnableKeyword("_VIEWMODE_ALPHA");
    26.                     break;
    27.                 case 5:
    28.                     m.EnableKeyword("_VIEWMODE_DESPILL");
    29.                     break;
    30.             }
    31.         }
    But in builds, this function doesn't seem to do anything at all.

    Is this a known issue?
    Is there something I'm doing incorrectly?

    This is the blackboard setup of the property:
    upload_2022-9-16_17-29-20.png

    Any help would be appreciated. Thanks!