New texture starts as white semi transparent?

I’m creating a new texture (for a mini map) like this

MyPixel = new Color(0.2F, 0.3F, 0.4F, 0.5F);
				
		pixelTexture = new Texture2D(mapSize.x*16, mapSize.y*16);


		int x = 0;
		int y = 0;
		int yHeight = mapSize.y;
		int xWidth = mapSize.x;
		
		for (int iy = y; iy <(y+yHeight); iy++) {
			for (int ix = x; ix <(x+xWidth); ix++) {
				
				
				TileInfo tileInfo = Tile.GetTile (new Int2(ix, iy), 5);
				
				if (tileInfo.set == 0 && tileInfo.tile == -1) {
					int s = 0;
				}
				else
				{
					SetMiniMapTile(MyPixel, ix*4, iy*4, 4);
				}
				
			}
		}
		
		pixelTexture.Apply();

		rend2 = gameObject.GetComponent<SpriteRenderer>();

		pixelSprite = new Sprite ();

		pixelSprite = Sprite.Create(pixelTexture,new Rect(0,0,mapSize.x*8,mapSize.y*8), new Vector2(0,0),2);
				
		rend2.sprite = pixelSprite;

What I don’t understand is that most of the texture is white/semi transparent, but I never set it to that, why is it like that? and how can I change it?

42618-screen-shot-2015-03-15-at-114022.png

When you create an array in c# it will be initialized with the type’s default value, for UnityEngine.Color this is (0, 0, 0, 0). So you can create an array of colors and set it on the texture to immediately have a transparent texture. You could also loop through this array and set the pixel colors that you want then upload the entire array at once.

    public static void FillTextureWithTransparency(Texture2D texture)
    {
        Color[] colors = new Color[texture.width * texture.height];
        texture.SetPixels(colors);
        texture.Apply();
    }//FillTextureWithTransparency

There is some overhead associated with passing data back and forth from the CPU and GPU, but as long as you’re not doing it per frame you should be fine. Also keep in mind that if the textures are large, these color arrays could potentially be large buffers being thrown off for garbage collection. If you do this with large textures, or you need to do it often, you could cache the Color

    private static Color[] colors;

    public static void FillTextureWithTransparency(Texture2D texture)
    {
        if (colors == null || colors.Length < texture.width * texture.height)
            colors = new Color[texture.width * texture.height];

        texture.SetPixels(0, 0, texture.width, texture.height, colors);
        texture.Apply();
    }//FillTextureWithTransparency

I personally find it odd and frustrating that Unity does not fill textures with transparency by default.