Texture2D GetPixel, and IsReadable, performance etc.

Hi guys,

Just wondering what sort of performance impact GetPixel has, if only ever called maximum of once on any frame or OnGUI repaint?

Also are there any side effects of enabling read/write on your imported textures?

Lastly, is there any other/better way to get the alpha value of a pixel on a texture. I suppose I could cache coordinates, not sure if that would end up having a worse impact though.

A single GetPixel call won’t be noticeable. Enabling read/write on textures means they will be stored in both RAM and VRAM. (Note that this was standard Unity behavior until sometime after 2.1; it was first introduced in Unity iPhone.) It would be slightly faster to do GetPixels on the entire texture once and read the color values from the resulting array from then on, but probably not enough faster to be worth the bother.

–Eric

Thanks, it looks like this is a possible solution for getting pixel perfect GUI click-through prevention. The GUI textures won’t be huge so storing them twice in memroy should be okay.

Interesting that it used to be standard behavior anyway.