Search Unity

Question Enum keyword switching does not work in standalone player

Discussion in 'Shader Graph' started by alloystorm, Nov 3, 2019.

  1. alloystorm

    alloystorm

    Joined:
    Jul 25, 2019
    Posts:
    88
    2019.3.0b8 HDRP 7.1.2

    I have an enum keyword "MASK_MODE" with 3 different states and "Definition" set to "Multi Compile". I'm setting those states at runtime with

    Code (CSharp):
    1. material.SetFloat("MASK_MODE", mode);
    This works fine in editor play mode but doesn't work in player.

    When I change the default value in editor and build, it renders that mode correctly but changing the value at runtime in the player has no effect at all. All variants of the shader are present in the player since I tried adding objects with different "MASK_MODE" values to the scene and they all render correctly.

    I've also tried setting keywords (MASK_MODE_X) directly when changing MASK_MODE value with no luck.
     
  2. AA-Matt

    AA-Matt

    Joined:
    Oct 1, 2016
    Posts:
    8
    For keywords you have to use `material.EnableKeyword("MASK_MODE_X")` and disable the other enum keywords with `material.DisableKeyword("MASK_MODE_Y")`.
     
    swingingtom and tonytopper like this.
  3. tonytopper

    tonytopper

    Joined:
    Jun 25, 2018
    Posts:
    226
    Struggling with this myself and this is what I was afraid was the case. Feels like a half-baked API.
     
    swingingtom likes this.
  4. Humblebee08

    Humblebee08

    Joined:
    Sep 2, 2014
    Posts:
    3
    Did anyone find a workaround for this? I'm encountering this issue myself when trying to build in Windows.
     
  5. Humblebee08

    Humblebee08

    Joined:
    Sep 2, 2014
    Posts:
    3