"Gizmos.Draw..." color's alpha is really buggy.

Hi. I am making a 2D MapEditor (C#), and using Gizmos.DrawLine to draw the grid, and Gizmos.color to set the desired color for the grid.

Everything works nicely, except the Alpha value.
In the Color Selection window, when changing the Alpha value around, only the values from 0 to 6 works (or #00FF4B00 to #00FF4B06).
This is very frustrating because I can only slide the slider a few pixels. If it goes over 6, the color is completely solid.
Am I doing something wrong here, or is it a bug in Unity?

Code:

// Creating the color variable
private static Color gridColor = Color.white;
/* … */
// Open the color selection window
gridColor = EditorGUILayout.ColorField(gridColor, GUILayout.Width(150));
/* … */
// Drawing the grid lines
Gizmos.color = gridColor;
Gizmos.DrawLine…

A little update. I checked if the grid was drawn over each other (so the alpha would be multiplied), but that was not the case. I tried to draw only one of the lines, but the problem was still there.

Do you have script attached tomorrow than one object?

No, I have only one script, which is in the Editor folder.
It is not attach to any objects. It is run automatically since it is in the Editor folder, and I have the Editor Window open.

Somehow, when I divided the gridColor.a with 100, it works much better (the opacity doesn’t suddenly go to solid after 6/255.

Color tmp = gridColor;
tmp.a = tmp.a / 100;
Gizmos.color = tmp;

I tried to put the alpha value in the console (Debug.Log), and the range was as it should (it went from 0 to 1).
Now, when it “works” (divided by 100), the alpha value goes from 0 to 0.01.

1 Like