Check if every pixel of a texture is transparent

Hello

I am currently trying to check if a texture is fully transparent. Basically, check if there’s absolutely nothing on the texture. I am generating these textures at runtime and it can happen that there’s nothing on the texture because of the lack of renderers on an object, and if there’s nothing there, I want to take care of it in some other way. But I don’t have any idea how I could check every pixel of a texture to see if it’s 100% transparent.

Any help with this would be greatly appreciated!

Thanks

just do a for loop:

bool IsTransparent(Texture2D tex) {
    for (int x = 0; x < tex.width; x++)
        for (int y = 0; y < tex.height; y++)
            if (tex.GetPixel(x, y).a != 0)
                return false;
    return true;
}

If you also need to check if all color values are 0, then just change the if statement to if (tex.GetPixel(x, y).Equals(new Color(0,0,0,0))). Sure, you could define the color 0 0 0 0 as a variable and use it so no stack/heap allocation occurs.