- Home /
Shader Graph Edit Parameters From Script
Hello,
I have made a simple shader graph that has an inline effect and i need it to have alpha transparency to edit it by code, however everything is working in the inspector but in code when i call material.color it gives me an error saying "Material doesn't have a color property '_Color'" and if i call material.SetFloat(string name, float value) it just does not affect anything.
Note:
the float name is "Alpha"
the color name is "Color"
In my case I can acces material.color, but it doesn't change anything, and SetFloat(), SetColor(), etc also doesn't work. Have you managed to find whats wrong?
Answer by davidcox70 · Jun 03, 2018 at 01:37 PM
You're on the right lines, but the name you need to target is different for shader graph generated shaders. In the inspector for your object, click the cog icon next to the material and choose "select shader". You'll get an inspector like this:
The name you need to target are the ones down below, such as "Vector3_895C57D6", created by Unity.
DC
Answer by Tarrag · May 23, 2019 at 09:45 AM
or change here within shader graph https://blogs.unity3d.com/2018/07/10/2018-2-is-now-available/#property
Answer by frankadoriv · Sep 05, 2018 at 08:20 AM
"The name you need to target are the ones down below, such as "Vector3_895C57D6", created by Unity."
This is a joke right?
C'mon unity team, WTH?
It ain't so bad. You can edit the name to something more sensible in the Shader Graph. So your code should look something like this: $$anonymous$$y$$anonymous$$aterial.SetColor("_$$anonymous$$yColor", Color.red);
Answer by Jason-Michael · May 08, 2019 at 12:39 PM
A little bit supplement, if you think the property name is kind of complex to type, you can open the .shadergraph file and search the paratermeter name shows in top left corner of Shader Graph window, in the same long line, you can find a "m_DefaultReferenceName" key value pair, which value is the property name you can use to set in C#.
Answer by MagyarPeter · Sep 18, 2021 at 12:59 PM
Set the desired color's reference to "_Color" (The REFERENCE, not the NAME)