- Home /
ReadPixels Screen is Offset
I'm using ReadPixels to capture the screen, but the texture always comes out quite a bit offset from the top.
This is the code I'm using:
Texture2D tex2d = new Texture2D(Screen.width,Screen.height,TextureFormat.RGB24,false);
tex2d.ReadPixels(new Rect(0,0,Screen.width,Screen.height),0,0,false);
tex2d.Apply();
Here is what the Screen looks like:
And here is the result from ReadPixels:
Edit: It seems that ReadPixels is also reading pixels from the Unity editor. Here is another example:
The first image is what the screen looks like, and the second is what ReadPixels produces.
As you can see, a portion of the editor is being read along with the screen. How can we solve this problem?
It seems that ReadPixels will read a portion of the editor if you call it too quickly, such as in a Start method.
Probably because the main camera hasn't been set to the game camera etc. Does this problem persist after the game starts running?
It doesn't persist after the game starts running. To fix this, just wait a second before calling ReadPixels. However, I don't see why it shouldn't work correctly without having to wait. This is a bug as far as I'm concerned.
$$anonymous$$mm. Not sure about that. You could be right but there may be good reason for it. I guess there's no harm in submitting it as a bug - if it is, it will get fixed at some point. Until then, the work around is obviously no biggy :)
Your answer
![](https://koobas.hobune.stream/wayback/20220613080121im_/https://answers.unity.com/themes/thub/images/avi.jpg)