Search Unity

Resolved Changing Value Of Exposed Boolean In Material

Discussion in 'Shader Graph' started by alanmthomas, Apr 15, 2019.

  1. alanmthomas

    alanmthomas

    Joined:
    Sep 7, 2015
    Posts:
    197
    I understand how to get and set a material's property block, but how does one go about changing the value of an exposed boolean parameter in a material? I can't find any method for doing so.
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    Boolean material properties are "fake", Unity doesn't actually support serialized (aka saved) boolean values on material assets. So instead they're really float values that are set to 0.0 or 1.0. The material inspector knows it's supposed to be a boolean, so it shows the check box in place of the float value, but from the script side it's still a float.

    TLDR: .SetFloat("_MyBoolean", myBoolValue ? 1f : 0f);
     
  3. alanmthomas

    alanmthomas

    Joined:
    Sep 7, 2015
    Posts:
    197
    THAT...
    IS...
    AWESOME! Thanks so much for your help!
     
  4. pablo_yt

    pablo_yt

    Joined:
    Jul 13, 2017
    Posts:
    1
    waaaauuuuuu!!!!
    Thanks