- Home /
Unity 3.5 New texture2D not transparent
Hi just upgraded my project to 3.5 and found out that when creating a new texture2d the default colour is white not transparent like 3.4.
Is there an easy way to change every pixel to transparent before I start creating my texture? Should also mention I don't know the dimensions of the texture until its being created so don't think I can just get all the pixels from a transparent texture of the same size.
Its a shame the constructor doesn't have a background colour option.
Answer by Eric5h5 · Feb 26, 2012 at 09:01 PM
There isn't any default color and never was; the pixels in a new Texture2D are always empty (i.e., undefined).
var tex = new Texture2D(64, 64);
var texColors = new Color32[64 * 64];
for (color in texColors) color = Color.clear;
tex.SetPixels32 (texColors);
tex.Apply();
just worried about the speed of that operation since at times I may be generating textures multiple times a second. As for the default colour, all I know is in 3.4 the pixels I hadn't set where transparent now there white [shrug]
As I said, the pixels are undefined. They might be transparent, or white, or whatever, depending on whatever happens to be in memory. The speed is trivial, and you could make thousands of textures per second...except for the tex.Apply() part. When you create a texture, it has to be uploaded to the graphics card, which can take a relatively long time for larger textures. I don't know what you're doing, but you might want to use rendertextures ins$$anonymous$$d.
Cant use render texture as I'm currently using free, (Basically since I cant think of a better way to do it) I have a texture with number images 0-9 in, I'm using GetPixels grab the numbers and set pixels to place them into a new texture2D, applying once all the sets are complete then using it in a newly instantiated particle system to draw a floating damage number (tried a GUIText method but it refused to look good)
Actually I'd strongly recommend GUIText ins$$anonymous$$d. I did something similar quite a while ago (http://www.starscenesoftware.com/tmfppg.html if you have a $$anonymous$$ac); there's no reason you can't get it to look good.
problem with GUIText is i cant get it to look great in 3D im going for a borderlands style effect, the particle system has been the best so far and was working fine untill 3.5. Guess ill have to try and find another way of doing it, or some other work around the get the background transparent.
Your answer
![](https://koobas.hobune.stream/wayback/20220613064516im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
ingame transparency 2 Answers
Check if every pixel of a texture is transparent 1 Answer
Can I get Direct3D pointer of Texture2D in Unity3.5? 8 Answers
EncodeToPng that works more smoothly on mobile 1 Answer
async texture apply (WebPlayer) 1 Answer