Search Unity

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

Discussion in 'Editor & General Support' started by CandyCreep, May 28, 2016.

  1. CandyCreep

    CandyCreep

    Joined:
    Apr 28, 2016
    Posts:
    3
    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...
     
  2. CandyCreep

    CandyCreep

    Joined:
    Apr 28, 2016
    Posts:
    3
    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.
     
  3. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    9,051
    Do you have script attached tomorrow than one object?
     
  4. CandyCreep

    CandyCreep

    Joined:
    Apr 28, 2016
    Posts:
    3
    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.
     
    igorobm likes this.