Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Support both VR and non-VR in the same app (esp. UI)

Discussion in 'AR/VR (XR) Discussion' started by SimRuJ, Jan 15, 2019.

  1. SimRuJ

    SimRuJ

    Joined:
    Apr 7, 2016
    Posts:
    247
    The app I'm working on has to run in three different environments:

    A. Non-VR (desktop PC or Windows tablet with keyboard/X1 controller/touchscreen controls)
    B. Non-VR with Anaglyph 3D (desktop PC with keyboard/X1 controller)
    C. Windows Mixed Reality (e.g. HMD Odyssey with Steam VR; desktop PC/notebook with keyboard/X1 controller)

    1. For A and B (the nVidia drivers take care of the 3D) I can just export my app as "PC, Mac & Linux Standalone". For C I have to add OpenVR in the "Player - XR" settings. Is there any setting that makes it possible to export the app for A, B AND C, so I can just give out a single version (that supports VR and non-VR) to the players?
    If I just export with OpenVR enabled and start the app without any headset connected, SteamVR starts up anyway and I get an "Hmd Not Found" error message. The app still works but I'm not sure how to get rid of the error message without connecting a WMR headset.

    2. What specific settings do you need to have menus for WMR and non-VR in a single project?
    Currently I have my main/pause menu set up like this:
    An extra UI camera that's the child of the Main Camera (at -1000 z) and that only renders the Canvas (at -900 z, the UI camera is set as its "Render Camera"), while the Main Camera sees everything but the UI (set through the Culling Mask). In the actual game scenes the Main Camera is additionally a child of the player GameObject, so the pause menu is always the same distance from the player, no matter where he is.

    In non-VR mode I disabled looking around when you're in a menu (main/pause) but they have to be centered of course, so they're visible properly.
    In VR I can't disable looking around, so the menus have to stay in one spot and I can't have them move with the head movement the way they are now.
    No matter if it's with VR or not, the menus have to be in front of the player and I'm not sure how to do that without either having a special camera (the way I currently do) or moving the whole canvas (which is a problem with overlays that are always there for e.g. special options).

    3. If a WMR headset is connected, should you give the player a choice whether he wants to use it or play in non-VR mode? Or should it just depend on what devices are connected?
     
  2. SimRuJ

    SimRuJ

    Joined:
    Apr 7, 2016
    Posts:
    247
    1. I opened an extra thread for the "Hmd Not Found" error message here.

    2. I now change the menus depending on if there's a WMR headset connected or not:

    Default:
    - MainCamera: Solid color, Culling Mask: everything except UI, depth: 0, at (0,0,0)
    - UICamera: Depth only, Culling Mask: only UI, depth: 1, at (0,0,0)
    - Canvas: "Screen Space - Camera" that uses the UI camera, at (0,0,100) because of "plane distance = 100"

    VR:
    - Cameras are the same
    - Canvas:
    Code (CSharp):
    1. if(vrmodeenabled) {
    2.     canvas.renderMode = RenderMode.WorldSpace; //switch to WorldSpace
    3.     canvas.transform.position = new Vector3(0,0,200); //move the canvas back a bit
    4. }
    This keeps the menus in a specific spot (instead of moving them with the camera like in non-VR mode), so you can look around without them moving with you. It also keeps the menus in front of everything (even if they should be behind something for correct visibility).
    If the player can move around, you have to move the menu to "(player.x, player.y, player.z+200)" of course and rotate it accordingly (e.g. for a pause menu that's always in front of the player).
    Also noteworthy: Looking around using a VR headset makes the UI camera rotate twice as fast as the MainCamera - I posted a fix in my thread here.

    3. How does everyone do that? I tried detecting and changing it automatically but that keeps looping me back to the "Hmd Not found" problem (check the thread I linked for 1.).