1
\$\begingroup\$

I have a Shader Graph shader with a blackboard property that I want to change from within my code. The property is called Highlight here are the things I have tried:

Color myColor = new Color(1f,0,0,1f);
material.Color = myColor;                       // throws error (as I expected)
material.SetVector("Highlight", myColor);       // Name in blackboard window
material.SetVector("HighlightColour", myColor); // Name in material property
material.SetVector("Color_8C3A526", myColor);   // Name in the shader inspector

None of these work.

Here's the shader set up: The Unity Shader Graph showing a fresnel shader with a Highlight property in the blackboard

\$\endgroup\$
2
\$\begingroup\$

In Unity 2018.2, they've added an editable Reference Name for properties in shader graphs, letting you replace these unfriendly generated names like Color_8C3A5256 with semantically meaningful names.

You can now edit the Reference name for a property, making it far easier to reference your shader properties from script. To do so, select the property and type a new name next to Reference. If you want to reset to the default name, right-click Reference, and select, Reset reference.

In the expanded Property window, you can now also toggle the Exposed checkbox.

Screenshot of property editing window with reference name field selected.

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

To set the colour in the Shader use:

Color myColor = new Color(1f,0,0,1f);
material.SetColor("Color_8C3A526", myColor);

Although the blackboard parameter color is "Highlight", it has a unique codename that you can find by opening the inspector and selecting (but not opening) your shader graph. The shader in the question looks like this:

enter image description here

The Highlight colour appears under Properties and has the unique key of Color_8C3A526. If you change the name of Highlight in the shader graph tool then the unique key will remain the same.

Thank you to @DMGregory, who got me most of the way there.

| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.