Hello, fellow Unity Developers.
I am facing a weird issue after having upgraded my project from Unity 2019.2.21 to Unity 2019.4.2. The Texture2D.ReadPixels in the iOS project is returning a black texture in my iPad 6th generation running iOS 13.5.1. It worked all fine in Unity 2019.2.21, but in almost all editor versions post 2019.3.0, I am not able to capture a screenshot in my unity iOS app.
In this Unity ARkit based project, I am just upgrading the Unity version to be able to use the latest Depth API features available in AR Foundation & ARkit 4.0.2. Now, surprisingly enough, the same upgraded project works fine in Unity Editor as well as an Android device with ARCore, but I don’t understand why the ReadPixels texture is always coming black on the iOS app in my iPad.
In my project, there is a Take Screenshot button which simply invokes a Coroutine that Reads Pixels of the Screen to a Texture2D and then shows it on a UI.RawImage. The Coroutine is as below:
private IEnumerator CaptureScreenShot()
{
yield return new WaitForEndOfFrame();
var screenShot = new Texture2D(Screen.width, Screen.height, TextureFormat.RGB24, false);
screenShot.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0, false);
screenShot.Apply();
OnScreenShotCapture(screenShot);
}
This works fine in the Unity Editor but it always comes black in the RawImage on the iPad. Now, I tried replicating this behavior in a new project made with Unity 2019.4.2 with a simple button and the same code of capturing a screenshot, and surprisingly, it worked there. I was able to capture the screenShot with a new project made with Unity 2019.4.2, but somehow not with my upgraded project.
I have tried upgrading the same project to Unity 2019.3.0, Unity 2019.3.15, Unity 2019.4.2, and Unity 2019.4.3; but the same result in all the iOS builds, black texture instead of the screenshot. And the weird part is if I downgrade back to Unity 2019.2.21 from any of the above versions, it starts to work normally and the ReadPixels texture returns the screenshot as expected.
I dug the internet for possible solutions, but none of them seem to work for me right now. I tried Application.CaptureScreenShot() and ScreenCapture.CaptureScreenshot() both, instead of the ReadPixels, but they save the error image with a red question mark instead of the actual screenshot in my case.
Is anybody else facing such an issue, maybe with an old iOS project when upgraded to Unity 2019.4.2?
What should I do to resolve this? Kindly suggest things to try to maybe work around this.
Please help!