Request: Color.transparent

Today when I was working with the Color struct and I noticed it lacks a .transparent implementation. It would be nice if that were to be added.

Please enter the poll so Unity can see if there is any interest in this feature. Thanks!

That would be color.a (alpha), and it exists :slight_smile:

You can use the alpha channel for transparency Unity - Scripting API: Color.a

Unity has one transparent color, named Color.clear. That’s all 0’s (so black) and the name feels zero-y. I think I’ve seen other systems with “transparent black” and “transparent white”.

The problem is that the color might also matter. It won’t for a fully-transparent alpha of 0, but it might later be changed to be not-so-transparent. Maybe it’s blended with an adjacent pixel, or maybe some other step modifies it. So now you’ve maybe got mostly transparent black, (0,0,0,0.1), which might darken a light background in a way you didn’t want. Or you’ve got a dark background and almost-transparent white, (1,1,1,0.1) is making it too bright.

In practice it’s better to set the color to the background, or to the “normal” sprite color, then set alpha to 0. Built-in transparent white (or black) won’t help with that.

3 Likes

I have a feeling that the request has been misunderstood by all but Owen-Reynolds.

2 Likes

If that’s true, what would be the exact .transparent implementation here what we don’t already have? Maybe I’m a bit slow today.

This is one of those “guess what they’re asking” Q’s. Down in the body it asks for an implementation. That generally means just some way of doing it. The answer to that is what Vhars and karl wrote – it already has one.

But up in the title it asks for the specific new preset constant Color.transparent. My guess was the poster merely misused “implementation” in place of uh, “constant” or “feature” or “enum”. But my other guess is maybe they don’t know you can also make colors with new Color(r,g,b,a). They think you have to use built-ins and they’re really asking for just any way to make a transparent color. In other words, they are asking for an implementation and assume Color.transparent is the only way to do it. In which case Vhars and karl are correctly pointing out how it’s an “X/Y” problem and are giving the real answer (X/Y as in: I want to do X, but am incorrectly asking about Y since I assumed Y is the first step in doing X).

If this Q was on StackExchange it might be closed until they could clarify and clean it up (or not – SE:gameDesign/Unity isn’t that great).

So far up the Ladder of Inference from just one word…

Edit: Which applies to me, too. :slight_smile:

You can make an extension method.

public static class ColorExtensions{
    public static bool isTransparent(this Color arg){
        return arg.a < 1.0;
    }
}

I suspect the op just didn’t understand the .a value. Transparent : alpha=0f. Opaque : alpha=1f

1 Like