- Home /
ReadPixels to capture GameView in EditMode and "Pixels out of bounds"
Hi,
I'd like to create snapshot a series of frames from the editor Gameview window using ReadPixels. This works to some degree, but I get the "Pixels out of bounds" error randomly.
My guess is that this error occurs if I try to capture the screen while the frame isn't completely rendered. At runtime I would use yield WaitForEndofFrame() to take care of this, but yielding isn't possible in Editmode.
I tried to place my code inside EditorWindow.Update() and to hook into EditorApplication.update - doesn't matter, the error occurs randomly. Using OnGUI() works if I just take one screenshot triggered by a GUI button, but I need to render and snapshot several frames, and the GameView won't update using GameView.Repaint() inside the ONGUI call. I tried to spread this to several OnGUI calls (by forcing GUI repaiting), but then I got "Pixels out of bounds" again.
I really appreciate any help on this topic
Jake
Answer by Zebibto · Aug 15, 2013 at 02:01 PM
I was trying to take screenshots of the SceneView to no avail. So this little script takes screenshots of the active GameView.
Add the component to the camera you want to take shots with and take a single or multiple screenshots. This works while in editor without the game running and also while the game is running, although the timing is probably messed up.
NOTE: The Gameview must be visible or the WaitForEndOfFrame never occurs and the screenshot never gets taken. You can also take the screenshot in OnPostRender like spectre suggested.
[1]: /storage/temp/14330-screenshottool.zip
Answer by entwisled · Aug 10, 2013 at 02:35 PM
I have exactly this issue, but I only want to get on screenshot. Did you ever work-out a work-around?
Answer by spectre1989 · Aug 11, 2013 at 12:23 PM
Try putting the script on the camera, and calling ReadPixels in OnPostRender.