Search Unity

Question Set Gradient Node Value from Script

Discussion in 'Shader Graph' started by owen_proto, Oct 7, 2019.

  1. owen_proto

    owen_proto

    Joined:
    Mar 18, 2018
    Posts:
    118
    I've found that you can set a gradient as a property in a shader and sample it for a color using the sample gradient node, but I cannot find info on how to set the value of the gradient property from a C# script.

    It would be helpful to know how to do this directly to a material (i.e. "material.SetGradient") and for a MaterialPropertyBlock.
     
    MrDizzle26 likes this.
  2. alexandral_unity

    alexandral_unity

    Unity Technologies

    Joined:
    Jun 18, 2018
    Posts:
    163
    Gradients are not a supported material property, that implementation is specific to Shader Graph. The intent of it being on the blackboard is to re-use the same gradient in multiple places, but the material doesn't support it as a property, limitation of Shader Lab.
     
    owen_proto likes this.
  3. JG-Denver

    JG-Denver

    Joined:
    Jan 4, 2013
    Posts:
    77
    Is there any way around this limitation today? I need to be able to set gradient changes at runtime from code.

    Thank you!
     
    MrDizzle26 likes this.
  4. Gabo_6480

    Gabo_6480

    Joined:
    Jan 26, 2021
    Posts:
    1
    I guess the closest thing would be creating a texture containing the gradient and using that instead.
    However I am dishartened as well to hear that it is not posible otherwise.