- Home /
Color field set in the Inspector is transparent when run.
I'm trying to set up a color that can be edited from the Inspector. Obviously, it starts with this:
public Color myColor;
And I get a color-picker on the component, as expected. The problem is, the selected color doesn't take effect; it winds up being Color.clear
at runtime. Here's a simplified version of my code, in case any of it is relevant:
void Start() {
cells = new Dictionary<MyCellIndexType, Renderer>();
foreach (MyCellIndexType cell in GetPlayfieldCells()) {
cells[cell] = SpawnGameObjectReturningRenderer();
cells[cell].material.color = myColor;
}
}
The objects are all created, but transparent. If I add this line to the top of Start()
...
myColor = Color.green;
...they're all green, so the rest of the code is working as expected; myColor
just isn't making it from the Inspector to runtime. I've tried adding [SerializeField]
on the declaration, to no avail. Any clues?
Solved: Alpha channel defaults to zero. Thanks, Clet_!
Answer by Clet_ · Jun 04, 2014 at 11:16 PM
Check the alpha channel of the color you set in the inspector. Make sure that it is set to 255 if you want solid color. I had this problem once and I realized this was the cause.
In the inspector, in a color field, you always have a greyscale strip right underneath the selected color. Solid white means alpha = 1f, and solid black means alpha = 0f.
Well now I just feel silly. Would upvote your answer but apparently I need more reputation... edited the question to give you credit!
Rather than writing 'solved' in the title please accept his answer by pressing the tick:
P.S I forgot who ever made this graphic but thanks ^^
Aha, was looking for that, didn't think to check random unlabeled graphical embellishments. (Hey, that's the same issue that led to this question.) Thanks. Whatever happened to text? I blame Apple.
Your answer
Follow this Question
Related Questions
Material doesn't have a color property '_Color' 4 Answers
Changing two different objects renderer colour 1 Answer
Is there a way to get Editor background color? 4 Answers
(Inspector) Change Header Color 0 Answers
Issues with changing light colour 2 Answers