Search Unity

5.1 and Managing VR during runtime

Discussion in 'AR/VR (XR) Discussion' started by HankySpanky, Jun 24, 2015.

  1. HankySpanky

    HankySpanky

    Joined:
    Feb 3, 2015
    Posts:
    77
    I'm fairly new to developing on the Oculus and completely so in the latest update of Unity, and as such, I don't know if what I'm seeking is feasible or not without resorting to more complex measures than what is available out of the box.

    My primary concern being the ability to enable/disable the Oculus at will during runtime. In the most likely of scenarios, starting up a scene without the Oculus turned on, and then turning it on as the scene progresses. Essentially supporting VR in the project regardless of whether a device was connected at the start or not.

    In the long run I want to be able to catch the event when a device is connected/disconnected and give the player the option to enable VR if a device is present. And similarly, revert back to the basic view if a device is removed.

    I've been testing the new VRDevice class available in the Unity.VR namespace, most notably the isPresent property, and so far it has turned up mixed results.

    If I run the scene with the Oculus turned off, VR, from the looks of the console seems to be excluded from the build, and from that point on, turning on the Oculus does nothing. isPresent contains false in all cases.

    However, if I keep the device turned on and run the scene, the device is detected normally. And from that point on, I can disconnect/reconnect it and the scene is displayed in the device regardless. Although isPresent contains true always, which I find a bit odd. I would expect it to revert back to false after disconnecting the device.

    Although I'm still not entirely sure what I'm asking about. My question is, is there a general way to approach management of the Oculus during runtime that's so far been used in the old Oculus plugin and could be applied to Unity 5.1 as well?

    PS: If something about this post comes off as particularly vague, do feel free to ask and I'll try my best to elaborate.
     
  2. EdBlais

    EdBlais

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    311
    The best current solution to this is to either us VRSettings.loadedDevice or VRSettings.enabled. http://docs.unity3d.com/ScriptReference/VR.VRSettings.html

    When you enable Virtual Reality Supported in the Player Settings, that allows you to use Virtual reality in your project. Oculus Rift and GearVR both fall under DeviceType.oculus. When you enable the player setting, the dll that is needed is automatically copied to your standalone builds. This dll is located in your Editor Install directory and will be referenced from that directory in the Editor. It will be copied directly to the Data/Plugins folder in builds.

    So, you enable Virtual Reality Supported and then you set VRSettings.loadedDevice to VRDeviceType.none when you don't want VR and when you switch to using the headset, you change VRSettings.loadedDevice to VRDeviceType.oculus. This will need to be done in script.

    Also, when you change the loadedDevice in the Editor, it will kick you out of Play mode. However, in standalone builds, It will switch the device on the spot. The scene will NOT restart in standalone, it will continue playing while the device is being switched.

    As for the isPresent check, that will always return either true or false depending on if Virtual Reality Supported is true or false. In the Future, we will have more options for VR Devices and isPresent will return based on which Device you are checking isPresent on.
     
  3. HankySpanky

    HankySpanky

    Joined:
    Feb 3, 2015
    Posts:
    77
    Thanks for the swift response. isPresent returning based on whether VR is supported or not quells some of my confusion in regards to what was happening, albeit, it seems a bit contradictory to the description in the documentation. But since it's still being worked on I suppose I shouldn't worry.

    Correct me if I'm wrong though, but am I to understand that if a VR device isn't detected initially during the build phase, despite the Virtual Reality Supported being set to true, the .dll is excluded from the build, and hence, sets VR to unsupported?

    In that scenario which I've recaptured a few times, if I leave the device off, or disconnected during the initial build, a warning appears in the console that seems to imply that VR is excluded from the project. Past that point, isPresent returns false. And plugging the device in or turning it on has no bearing on the settings or the device status.
    Again, as if VR is set automatically to unsupported because no device was detected at launch.

    If I do leave it on however, no warnings appear, and VR seems to remain supported. If I turn the device off and on at that point, it continues tracking from the moment that it was turned back on without warnings..

    If that is indeed the case, would it be a matter of simple configuration to mark VR as supported even though there is no usable device detected initially?

    I'm also slightly unclear still on how you'd currently check if a device is physically connected or not. And when it is removed during runtime. Because if loadedDevice needs to be set in script, wouldn't you have to make the assumption that a desired device is connected and that switching to it will succeed?
    As far as I can remember, if a device is detected initially, loadedDevice is set, but after that, even after disconnecting the device, loadedDevice doesn't revert back to none. It keeps the device type value, or in this case, Oculus.
    I can't confirm this yet as I'm not at a workstation with the device, but I intend to do so at first chance.

    I apologize if I'm treading over hints from your answer. I'm still trying to wrap my head around desired practices here.
     
  4. HankySpanky

    HankySpanky

    Joined:
    Feb 3, 2015
    Posts:
    77
    Update:

    It turns out that if a device is not connected right at the start, the following crops up:


    It requires a refresh of the project for the Oculus to start working again and to enable VR. But again, the Oculus must be enabled when the scene is run.
    But even if having the device connected at all times is acceptable, there is still the predicament of the Oculus always rendering its left eye view to the screen. Which is a problem in my scenario since I need to disable/enable normal view at will.
    Preferably beginning with the Oculus view disabled, and transitioning over at a certain point.

    There is a property in the VRSettings class that seems to imply functionality for exactly this purpose. But I haven't gotten it to work at all.

    The only property that seems to have any effect when changed is the enabled property in the VRSettings class. But this merely enables/disables the tracker. The view is still rendered to the Oculus, and the Oculus left eye view can still be seen on the main screen.

    Are there currently known workarounds to managing this transition through the official new UnityEngine.VR namespace or is the possibility for this type of configuration simply not available yet?