Search Unity

Canvas invisible with "Virtual Reality Supported" checked

Discussion in 'AR/VR (XR) Discussion' started by SimRuJ, Nov 27, 2018.

  1. SimRuJ

    SimRuJ

    Joined:
    Apr 7, 2016
    Posts:
    247
    Hi,

    I want to test my app (3D (as in "not 2D sidescroller") but haven't added anything for VR yet) with a 3D monitor, that's why I checked "Virtual Reality Supported" in the "Player" settings, added "Stereo Display (non head-mounted") to the list and removed "OpenVR" and "Oculus".

    But now my main menu and pause menu are invisible - they are both panels on a canvas set to "Screen Space - Overlay". I can still click the buttons in the menus and they do show up in Unity (both in the "Scene" and "Game" view), just not in the actual exported game.

    I read somewhere that "Screen Space - Camera" might work (I didn't add a camera, so it's still an overlay) but that didn't work. Other than that "World Space" was suggested but even after changing the position of the camera to work with that, it still doesn't display anything in the build (only in Unity).

    If I untick "Virtual Reality Supported", everything works fine again.

    Camera & Canvas:



    Are there any other settings I have to change?
     
  2. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    No, World Space is the right thing to use in VR. Go back to that, and just make sure it's positioned somewhere you will be able to actually see it.
     
  3. SimRuJ

    SimRuJ

    Joined:
    Apr 7, 2016
    Posts:
    247
    It is:


    But it says in the console:
    "Virtual Reality SDK Stereo Display (non head-mounted) is not supported in Editor Play Mode. Please Build and run on a supported target device."
    So in the end I have to export it to see the real result and that's when the camera fails to display any menus.
    I made the main camera the Canvas' "Event Camera" (check the second screenshot in post 1), is that maybe the cause of the problem?
    The monitor I'm currently using doesn't support nVidia 3D vision but I still get the invisible main menu with it, while all of the objects in the actual game show up - but without any side-by-side images (it feels like I'm getting less fps though).

    Plus, even though you're supposed to be able to move the camera with the Alt key, this doesn't work - neither in Unity nor in the build.
     
  4. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    OK, you've mixed a whole lot of issues into one message there. Best to take them one at a time.

    The camera preview shows what you'll see in the camera's default position. But as soon as you run with a headset, the camera moves and rotates according to what the headset is doing. So it might be behind you, or facing the other way, etc.

    You've got it placed in an empty scene, so it would be very hard to tell if it's invisible or you're just not looking at it. I suggest you make a more complete scene, with a plane and some boxes and whatnot, and attach the canvas to some prominent feature you can easily identify. Then go into VR. If you see the prominent feature without the canvas, then I'll believe it's really invisible.

    Otherwise, it's hard to believe, because I've been using Unity for years and have never seen a canvas just fail to show up, unless I've purposely hidden it from a camera using layers.
     
  5. SimRuJ

    SimRuJ

    Joined:
    Apr 7, 2016
    Posts:
    247
    There's no headset. The VR setting is set to "Stereo Display (non head-mounted)", so I can test it on the other monitor with nVidia 3D vision or anaglyph glasses. The monitor used with the PC Unity is installed on is just a normal non-3D one.

    The canvas is definitely there: The grey things you can see in my screenshot (post #3) are buttons and each of them basically loads a "level". If I click on where the upmost button would be, it actually loads the very first "level" with all of its objects. Same thing with the pause menu: If I click on where the "exit" button would be, it closes the app.
    Thanks for the tip with the planes, I set up a couple of colored ones and increased the far clipping plane for that to 2000 (from the default 1000), now the main menu is visible. Looks like having the camera at (0,-1000,0) and the Canvas at (0,0,0) is a problem when you build it with VR mode, even if the monitor doesn't support 3D.

    With this a new problem has come up though:
    The canvas isn't filling the screen anymore if its render mode is set to "World Space". Its size is 1080p, Unity is set to 1080p and my monitor's using 1080p too, yet there's a small border around it.
    I found this post about how to show a canvas as an overlay in VR/3D (I also set the main camera to not render UI, so there's no conflict in non-VR mode) but even though the size is back to normal, the buttons are now messed up:


    They should all be the same size but one is covering the other ones and the text is missing. Hovering over the big one (they change color on hover) also displays other text.
     
  6. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    Ah. So this looks like some weirdness particular to your non-head-mounted stereo display (which I bet doesn't get a lot of testing).

    I'm afraid I'm out of ideas at this point, and have no experience with that sort of hardware... hopefully someone else can chime in.
     
  7. SimRuJ

    SimRuJ

    Joined:
    Apr 7, 2016
    Posts:
    247
    @JoeStrout
    Found the cause of the problem after replicating everything in a new project:
    Don't ever, ever (EVER) set a "Button" object as the chilld ("myButtonGO.GetComponent<Button>().transform.SetParent(transform)"), use the actual GameObject instead. Doing "myButtonGO.transform.SetParent(transform,true)" causes the same problem btw, so either set it to "false" or just use the 1-parameter version.
    If you're using a prefab button to fill the ScrollView, you might also have to do "myButtonGO.transform.localPosition = Vector3.zero;" AFTER setting its parent. This moves the button to where the ScrollView is, otherwise it will end up in front/behind if the surrounding canvas isn't at (0,0,0) but the button prefab is.

    Just a general "VR" question:
    The way I set up the cameras (one for UI and the main parent one for everything else) should (hopefully) work with both VR/3D and non-VR/3D. Are there any other "tricks" to supporting both in the same project?


    Edit: Something weird I've come across:
    I enabled anaglyph 3D (red/cyan) in the nVidia settings and checked the "Stereo 3D" box in the "Configuration" window. This adds a tiny 3D effect in the main menu but in the actual "game" part nothing's 3D, the colors are simply off because of the red/cyan. If the "Stereo Display (non head-mounted)" option is disabled, the 3D works great (as good as it can be with anaglyph 3D). What's the point of that option then? I highly doubt that 3D vision would work with it enabled if even anaglyph doesn't.
     
    Last edited: Nov 29, 2018