GetPixel Returning Inaccurate Color

I have a script that simply assigns a float value to the alpha channel of a pixel in a texture, however when calling get pixel on the exact same position the value is slightly off which is actually causing a big problem in my case. The code is all fairly simple:

texture.SetPixel(x, y, new Color (0, 0, 0, originalValue));
float returnedValue = texture.GetPixel(x, y).a;
print("0v: " +originalValue + " Rv: " +returnedValue);

Here are the results:


GetPixel seems to be rounding numbers to seemingly arbitrary values. Once again these values have to be exactly the same, I can’t really work around that in any way. Please tell me there is a fix for this. Is there?

If you want the data to be exactly the same you’ll need to create a texture that uses a floating point format for RGBA. That probably means you need to create a RenderTexture in the ARGBFloat format. To understand what you see, multiply your originalValue by 255, and remove the fractional part, to get the value that will be stored in your 32-bit RGBA texture. Then divide that number by 255 and you’ll see the returnedValue. There’s nothing arbitrary going on.