What is the proper way to hide GUI elements during a screenshot?

I have an iOS app with very simple requirements. Hide some GUI elements (a few buttons and sliders), capture screenshot, and save to iOS “camera roll”.

I can get this to work fine when I build with “Development Mode” checked in Build Settings.

The problem arises when “Development Mode” is UNchecked.

The screencapture images are partially black, anywhere from 10-80% of the bottom of the image is completely black. No errors reported.

What I’ve tried:

  1. Application.captureScreenshot() is asynchronous. As such, you must “poll” the file system to see if the file is “done” being created. I’ve tried delaying this polling using a simple Invoke() as I thought it might be interfering with the capture.
  2. The ReadPixels() method, but this yields a 100% black image every time in addition to an error in the xCode debug console “OpenGLES error 0x0502 in /xcode_porject/Classes/iPhone_GlesSupport.cpp”
  3. Use 32 Bit Display Buffer as suggested here
  4. Tried WaitForEndOfFrame as defined here and variations of what is here
  5. Initializing capture in LateUpdate.
  6. Attaching screencapture script to camera initializing Application.CaptureScreenshot from OnPostRender. Identical results.
  7. QualitySettings.vSyncCount = 1; in a variety of places, no effect
  8. Delaying the “reenabling” of the gui elements even after Application.CaptureScreenshot coroutine has successfully generated image file discovered in poll to System.IO.File.Exists(). No effect.

I am at a COMPLETE LOSS as to the solution. 3 weeks of development, the project was finished, go to build beta distribution, uncheck “Development Mode” and the project comes to a crashing halt.

Is this a Unity for iOS Bug?

  1. try to enable VSync, this should not let capturing screenshot while frame rendering

  2. try to make screenshot in this method

  3. also you can create rendertexture, render camera once to this rendertexture, read pixels, copy it to texture2d and save it as file

  4. also try this example

Use a camera that does not render the GUI layer. You can also change the culling mask temporarily.