- Home /
How do I get the shader color-property to show up in the Inspector?
Here is the code that I just copied from the Shader tutorial:
Shader "Tutorial/Basic" {
Properties {
_Color ("Main Color", Color) = (1,0.5,0.5,1)
}
SubShader {
Pass {
Material {
Diffuse [_Color]
}
Lighting On
}
}
}
But when I look at the inspector, the "Main Color" is always white (1,1,1,1).
It's a necro post, but I started the tutorial too and had the same problem To have the color show up simple 'Reset' the shader, no need for all the other hassle :)
Answer by Jessy · Jul 20, 2010 at 10:54 PM
Here's how it works, in the Inspector. Whenever you switch the shader, it behaves as if Material.CopyPropertiesFromMaterial was used. So, any similarly-named properties in your new shader will inherit the values from the last shader that had them. Color is not white by default. The reason your default is overwritten, as white, is that the default material has a property named "_Color", and it is set to white by default. When you assign our own material, your "_Color" property won't be respected, so defining it is basically useless, but unfortunately necessary to not produce an error.
Answer by jashan · Jul 20, 2010 at 05:18 PM
Hm ... it seems that color _Color is somehow predefined to white by Unity. It might be serialized as such. I've added
_Color2 ("Test Color", Color) = (1, 0.5, 0.5, 1)
and that did show up with the correct color. So, my guess would be that you simply have to change the color in the inspector and cannot rely on the default value given in the shader (at least not for _Color; for any other variable name it works).
Answer by equalsequals · Jul 20, 2010 at 05:19 PM
I believe the problem here is that whenever you create a new Material it defaults to the Diffuse shader.
If you create a new material, change the color to 0,0,255,255 (blue) and then change the shader to something else like say, Decal you will see that the color does not change to that shader's default color.
So unless you write an Editor script that somehow automates and creates a Material with your specified shader, and skips defaulting to Diffuse all together, you're always going to start out with white.
I believe this is just something with the system that is built in that allows you to change shaders in your material without losing any custom data that you have created in the Inspector.
Cheers,
==
Your answer
Follow this Question
Related Questions
Material doesn't have a color property '_Color' 4 Answers
Create color changer in strumpy shader editor 1 Answer
Material doesn't have property '_Color' 4 Answers
Transparency cube shader? 1 Answer
GL.Color() has no effect on android 1 Answer