- Home /
SetPixels32 called with invalid number if pixels in the array
Firstly, "if pixels in the array". Well there's certainly pixels in the array but I'm pretty sure it's meant to be "of". Secondly, "Array size must be at least width by height of the mip level used." From the docs. This is not true, if I give SetPixels32 an array that's even 1 too big, it throws an exception even tho the docs say otherwise.
ps I'm sorry for the sarcasm, I was up until 9am staring at the profiler...
Yes, that's a spelling mistake in the error message, and yes, as far as I can tell from the code, the array needs to be exactly the right size, not more than the right size.
Answer by AngelHo · Dec 22, 2015 at 09:02 AM
int size1 = 2;
int size2 = 4;
Color32[] pixels = new Color32[size1 * size2];
Texture2D texture = new Texture2D(size1, size2, TextureFormat.RGB24, false, false);
texture.filterMode = FilterMode.Point;
texture.SetPixels32(pixels, 0);
texture.Apply();
Make sure the array passed SetPixels32 have the same dimension as the texture. When they have the different dimension, the error is encountered. The texture is single level in this example.
Hope it helps.