Search Unity

Changing color from C# doesn't affect shader's output color

Discussion in 'High Definition Render Pipeline' started by Just_Lukas, Oct 1, 2019.

  1. Just_Lukas

    Just_Lukas

    Joined:
    Feb 9, 2019
    Posts:
    34
    Yo, I'm trying to set emissive color from my C# script to my custom shader made in shadergraph. This is how my HDR color variable is defined:

    Code (CSharp):
    1. [ColorUsage(false, true)] // HDR color
    2. public Color outlineColor;
    and then Start() looks like this:

    Code (CSharp):
    1. this.outlineImage?.material.SetColor("_EmissiveColor", outlineColor);
    And shader graph's blackboard contains this:


    And "Color" is then directly plugged into "Emission" slot in my HDRP/Unlit master node. The problem is that if I change "outlineColor" in the inspector, the material emission color won't change on game start. Only if I hardcode the color into the code like instead of using "outlineColor" I use "Color.green".

    Am I missing something or is this a bug?

    Any help is much appreciated

    L
     
  2. elbows

    elbows

    Joined:
    Nov 28, 2009
    Posts:
    2,502
    If its like the other similar questions people asked in the past, try using sharedMaterial instead of material.
     
  3. Just_Lukas

    Just_Lukas

    Joined:
    Feb 9, 2019
    Posts:
    34
    Yea but this is an UI.image which doesn't have a sharedMaterial, so what should I do then?