I am writing an app which uses a native iOS plugin to render the background and I rely on the cameras clear flags to be “depth only” so that I can clear the screen with my native code plugin in OnPreRender.
However, I recently updated to the latest version of Unity (4.5.2 at this point) from version 4.3, and now it seems the clear flags are no longer working in iOS. The screen is always cleared to black, so that my native code rendered background is overdrawn. I also tried the “don’t clear” flag, and still the background is cleared.
When I put my code in OnPostRender it will render as normal, but then I am unable to use unity to render anything on top of the background. Note that I am using Unity Free.
Seems the clear flags are working fine for other targets than iOS.
well, thats because we do extra steps to make sure you have optimal performace (not clearing - exactly clearing - backbuffer will have huge performance hit). PreRender does indeed happen before clearing, so that wont help you.
What you can try as a workaround is to call GL.Clear yourself in your OnPreRender (before you drawing the background). Then you can even make your camera to “Dont Clear”, as you handle everything yourself. Please make sure you will clear both depth and color - otherwise you will get performance hit
Setting the cameras clear bits to “don’t clear” does not work, the setting is ignored and Unity will clear the screen to black before drawing anyway. Note that I am testing on an actual iOS device (iPad), while in the editor play mode the “don’t clear” bit is honored as expected.
My app used to work in Unity 4.3, as that version of Unity would respect the clear flags under iOS. Could this be a bug?