WaitForEndOfFrame not working in XR in Unity6?

As title says, I am getting an error in Unity 6 while using CaptureScreenshotAsTexture as following:

 IEnumerator CaptureCamera(string path, bool portraitMode)
 {
     yield return new WaitForEndOfFrame();
     Texture2D texture2D = ScreenCapture.CaptureScreenshotAsTexture(resolutionFactorInt);
...

This worked fine in 2023.2.20, after upgrading throws the following message:

CaptureScreenshotAsTexture() failed to generate texture! Was method called before the ‘end of frame’ state was reached?

Where obviously I am wating for end of frame. Only happens in XR.

So it seems that what applies to WebGPU now also applies to XR:

I used the workaround in there via async callback, and it also works in XR, still needed to add stuff like flipping the wrongly rotated RenderTexture, but now it works.

Great, another thing which is broken in XR now, good that there’s a workaround most of the time for all those nasty new Unity 6 XR related bugs (including patching the Graphics package…).

Could you please report this as a bug from within the Unity Editor by selecting “Help → Report a Bug…” and attach a reproduction project so our Customer QA team can take a look?

Please let me know the ticket ID (IN-XXXXX) once you’ve done so.

While recreating the issue in a test project I found out that it only does not work when VR is activated, but headset is inactive. It works if headset is active rendering.

In our application, we are doing exactly this: Deactivating the rendering of VR camera, switching to another camera for the screenshot, and switching back to the VR camera. We are doing this due to some other bugs related to dynamic resolution in XR (DLSS and co).

In this case it fails as described above.

Do you still want to have a test project? It’s easy to reproduce in there as long as the headset is connected, but not mounted.

If the behavior is different between 2023.2.20f1 and Unity 6, then I’d say it’s still worth investigating, yes.

1 Like

Here’s the ticket ID:
IN-99053

Great, thank you!