Search code examples
c#unity-game-enginevirtual-realityoculus

How to prevent mirroring of VR camera view to main monitor


I'm developing a VR application in Unity using the OpenXR plugin from XR plug-in management. By default, whatever is seen by the VR camera is also mirrored to the main computer monitor. In my specific use case, inside the VR headset, I only want the user to see the game scene, which I've successfully achieved. On the main monitor, I want to display a full-screen custom UI (built with Unity UI Toolkit), with only a small portion (a window) showing the view from the VR camera.

I've managed to achieve the desired monitor view by creating a second camera that moves with the main VR camera and renders its view to a target texture, which I then use inside a Visual Element in the UI Toolkit. However, while the main VR view is effectively "hidden" behind the UI on the monitor, I know it's still being rendered there, which seems inefficient.

Is there a way to send the VR camera's output ONLY to the VR headset and not have it render to the main screen at all?

Here are some specifics about my setup:

  • Unity version: "2022.3.9f1"
  • Using the "Oculus Rift"
  • I've checked the settings in the Unity Editor, but couldn't find any direct way to disable the mirrored view.
  • I'm open to solutions that involve scripting, tweaking Unity settings, or changes in the OpenXR configuration.

Any guidance would be greatly appreciated!

This is what it should look like: on the left - the computer screen, on the right - the view from the VR helmet This is what it should look like: on the left - the computer screen, on the right - the view from the VR helmet


Solution

  • XRSettings.gameViewRenderMode = GameViewRenderMode.None;
    

    Prevents rendering VR view on monitor (works only in Build version)