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

Enabling VR at runtime?? please help

Discussion in 'AR/VR (XR) Discussion' started by shaderbytes, Feb 5, 2016.

  1. shaderbytes

    shaderbytes

    Joined:
    Nov 11, 2010
    Posts:
    900
    Hi All

    So I want to publish a desktop application that is Vr enabled but that DOES NOT start up in VR. It should start as a regular application and changing to VR is an option available to users via clicking a button in my options menu system.

    I have googled around and tried several things already but cant find an exact working solution.

    So far it seems you obviously have to have vr supported checked in the playersettings when you publish your application.

    What other suggested then was to set VRSettings.enabled to false and also set the device equal to none. This almost works but sadly when lauching the game it first kicks into vr , my headset switches on etc .. and then exits to a regular game. After this I can re enable it via the menu system as I want but .. I dont want it to do the start and stop on application launch.

    I tried to get around this by creating a shortcut to my application exe and setting the command line params -vrmode none.

    This did fix the application not doing the start stop thing when launching .. but then I cant seem to activate it via the menu system anymore .. the mirrorred view shows it enters into a vr mode , but it freezes the application.

    here is my code the menu system interacts with to handle starting the vr at runtime :

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using UnityEngine.VR;
    4. using System.Collections;
    5.  
    6. public class OculusController : MonoBehaviour {
    7.     private ApplicationEventVO AEVO = new ApplicationEventVO();
    8.    
    9.     void Awake () {
    10.        
    11.         enabled = false;
    12.         VRSettings.loadedDevice = VRDeviceType.None;
    13.         VRSettings.enabled = false;
    14.     }
    15.  
    16.     private bool isOculusEnabled = false;  
    17.     private bool oculusDeviceLoadPending = false;
    18.     private bool occulusEnabledToggle = false;
    19.  
    20.     public void ToggleOculusMode() {
    21.         occulusEnabledToggle = !occulusEnabledToggle;
    22.         RequestOculusActivation(occulusEnabledToggle);
    23.  
    24.     }
    25.  
    26.     public void RequestOculusActivation(bool setToEnabled) {
    27.         if (setToEnabled) {
    28.             if (VRSettings.loadedDevice == VRDeviceType.None) {
    29.                 VRSettings.loadedDevice = VRDeviceType.Oculus;
    30.                 oculusDeviceLoadPending = true;
    31.                 enabled = true;
    32.             } else if (VRSettings.loadedDevice == VRDeviceType.Oculus) {
    33.                 isOculusEnabled = true;              
    34.                 ExecuteOculusActivation();
    35.             }
    36.         } else {
    37.             enabled = false;
    38.             oculusDeviceLoadPending = false;
    39.             isOculusEnabled = false;            
    40.             VRSettings.loadedDevice = VRDeviceType.None;
    41.             ExecuteOculusActivation();
    42.         }
    43.     }
    44.  
    45.     private void ExecuteOculusActivation() {
    46.         if(isOculusEnabled){
    47.             AEVO.eventType = ApplicationEventVO.ApplicationEventType.VR_ENABLED;
    48.         }else{
    49.             AEVO.eventType = ApplicationEventVO.ApplicationEventType.VR_DISABLED;
    50.         }
    51.         ApplicationController.dispatchApplicationEvent(AEVO);
    52.         VRSettings.enabled = isOculusEnabled;
    53.         InputTracking.Recenter();
    54.     }
    55.    
    56.    
    57.     void Update () {
    58.         if (oculusDeviceLoadPending) {
    59.             if (VRSettings.loadedDevice == VRDeviceType.Oculus) {
    60.                 enabled = false;
    61.                 oculusDeviceLoadPending = false;
    62.                 isOculusEnabled = true;              
    63.                 ExecuteOculusActivation();
    64.             }
    65.         }
    66.    
    67.     }
    68. }
    69.  
     
  2. shaderbytes

    shaderbytes

    Joined:
    Nov 11, 2010
    Posts:
    900
    Feel free to share your wisdom with me .. im ready to hear it all.... bump
     
  3. shaderbytes

    shaderbytes

    Joined:
    Nov 11, 2010
    Posts:
    900
  4. Mycroft

    Mycroft

    Joined:
    Aug 29, 2012
    Posts:
    160
    I was hoping to do the same thing, but haven't seen anything to indicate it was possible yet.
     
  5. abertrand

    abertrand

    Joined:
    Dec 7, 2015
    Posts:
    29
    Same here, been looking everywhere for a solution but no luck! Must be an incredibly common ask though since it's so difficult to get keyboard inputs, etc. in VR.
     
  6. Mycroft

    Mycroft

    Joined:
    Aug 29, 2012
    Posts:
    160
    I just found VRSettings.enabled . I don't have time to research this now, but it might be useful.
     
  7. shaderbytes

    shaderbytes

    Joined:
    Nov 11, 2010
    Posts:
    900
    You didn't read my post properly , this works but has usability issues .. read the post in full and see what is mentioned about it.
     
  8. Section-One

    Section-One

    Joined:
    Sep 8, 2014
    Posts:
    81
    You can always use the oculus sdk instead of the built-in feature...
     
  9. Mycroft

    Mycroft

    Joined:
    Aug 29, 2012
    Posts:
    160
    Nope, just forgot, because it had been awhile.
     
  10. SolidFabio

    SolidFabio

    Joined:
    May 18, 2015
    Posts:
    3
    I'm trying to do the same thing (if I understood shaderbytes point) to avoid my Android app to require GearVR to be connected. I want the user to select normal or VR mode in the first scene and then, if VR is selected, require the phone to be connected to Gear.

    How Oculus SDK can handle this?
     
  11. Section-One

    Section-One

    Joined:
    Sep 8, 2014
    Posts:
    81
    You could try having it disabled by default. I assume there's some checkbox on one of the prefab's objects.
    And enable it when you need to.
     
  12. shaderbytes

    shaderbytes

    Joined:
    Nov 11, 2010
    Posts:
    900
    In what way are you helping here? You assume there is some checkbox somewhere? Come now - this type of response is not very helpful. No hard feelings but just being honest.
     
  13. abertrand

    abertrand

    Joined:
    Dec 7, 2015
    Posts:
    29
    Incredible but true: this isn't supported. You can't have hybrid VR/Non-VR apps on the Gear VR. On Oculus forums, the Oculus mode's recommendation is to have two APKs if you want to have something in non-VR. Which, of course, is a great user experience!

    PS: I find that quite cynical by the way given the fact that Oculus's own Oculus Home app for the gear VR *is* a hybrid app...
     
    Last edited: Feb 20, 2016
  14. shaderbytes

    shaderbytes

    Joined:
    Nov 11, 2010
    Posts:
    900
    Hectic stuff! Totally sucks they tell us to have two versions and then they present their own built apps as one. I personally want it for oculus desktop , and I know it can be done as well since I have a non unity game on my machine which does exactly this as well.. launches as a regular game .. enable oculus at runtime via their menu!!

    Somebody needs to tell us their dark voodoo secrets on how this is being achieved ;)
     
  15. abertrand

    abertrand

    Joined:
    Dec 7, 2015
    Posts:
    29
    Have you tried contacting the devs of the app you mention? Between devs secrets can be shared ;)
     
  16. shaderbytes

    shaderbytes

    Joined:
    Nov 11, 2010
    Posts:
    900
    well the app sadly is no longer functional in VR anyway .. crashes ever since updates to direct mode after runtime 0.6 , I think it only used to work in extended mode. If they are not even bothered to update the app then im not sure they are bothered to answer anybodies questions about it either. It is Toy Box Turbos ,from code masters.. it was an excellent oculus experience, I wish they would update it!
     
  17. abertrand

    abertrand

    Joined:
    Dec 7, 2015
    Posts:
    29
    I'd say worth a try if you're really desperate. Like by finding some of the devs on Linkedin. But it's your call!
     
  18. steveh2112

    steveh2112

    Joined:
    Aug 30, 2015
    Posts:
    314
    i don't know what ApplicationEventVO is in the OP post, so i patched out those line. it disables the oculus fine but doesn't bring it back then i do this
    OculusController oc = GameObject.Find("OculusController").GetComponent< OculusController>();
    oc.RequestOculusActivation(true);
    any ideas?

    thanks
     
  19. cricentifrancesco

    cricentifrancesco

    Joined:
    Sep 12, 2016
    Posts:
    4

    Hi shaderbytes.
    Long time is passed but i exactly had the same issue today and i had to found a working solution.
    The only working way i found was to launch the application with the splashscreen On, infact if you enable the splash screen unity seems to have the time to load all what it needs ( I don't know exactly what happens ) Than you can set VRSettings.enabled= false in your first application scene. The splash screen will take just some seconds.

    That worked for me, if in other projects you'll find again this issue i hope that this solution can be helpful.
     
    taguados likes this.
  20. Hazneliel

    Hazneliel

    Joined:
    Nov 14, 2013
    Posts:
    305
    Cascho01 likes this.
  21. shaderbytes

    shaderbytes

    Joined:
    Nov 11, 2010
    Posts:
    900
    AH that is new , it didnt have this kind of logic before or was undocumented .. I will test it thanks
     
  22. FerryvD

    FerryvD

    Joined:
    Sep 9, 2016
    Posts:
    25
    Have you actually put on the headset?
    I had similar problems, it was working in the editor but in the build it seems to freeze, but it was just waiting for me to put on the headset.

    Hope this helps you.
     
  23. shaderbytes

    shaderbytes

    Joined:
    Nov 11, 2010
    Posts:
    900
    i cant test anything since I upgraded my project to a newer version of unity which now has issues using a .net 4 dll I have in my project. Unity dev says it is unsupported and the editor has errors now.. but this very same dll worked in unity 5.3x and 5.4x .. sigh
     
  24. PranavBuradkar

    PranavBuradkar

    Joined:
    Oct 15, 2015
    Posts:
    4
  25. LukeWaffel

    LukeWaffel

    Joined:
    Jun 21, 2013
    Posts:
    12
    It's not cynical at all actually. You say it's not supported, but this doesn't mean it's not possible. Opening the Android image picker in Unity also isn't 'supported' by Unity, yet it's perfectly possible to do so.
     
  26. Cascho01

    Cascho01

    Joined:
    Mar 19, 2010
    Posts:
    1,347
    I tried so and that way I was able to start my app in non vr-mode and to switch to cardboard-mode on GearVR.
    But how to switch back to non vr-mode?
    Hitting the cross closes the app.
     
  27. sonofbryce

    sonofbryce

    Joined:
    May 19, 2009
    Posts:
    111
    I don't think it's possible for this to work on Gear VR because of the changes to the AndroidManifest.xml that Gear VR requires.
     
  28. Hazneliel

    Hazneliel

    Joined:
    Nov 14, 2013
    Posts:
    305
    To go back to non vr you would have to implement your own UI element which calls a function that switches the VR Mode by calling: VRSettings.LoadDeviceByName("none")
     
    sonofbryce likes this.
  29. xipeluife

    xipeluife

    Joined:
    Jan 15, 2013
    Posts:
    14
    sonofbryce likes this.
  30. tobermanar

    tobermanar

    Joined:
    Aug 17, 2016
    Posts:
    9
    Hi guys,

    This solution doesn't seem to work anymore. Does anybody found a solution to create an Hybrid app with Gear VR (Oculus) SDK ?
     
  31. Cascho01

    Cascho01

    Joined:
    Mar 19, 2010
    Posts:
    1,347
    UnityEngine.XR.XRSettings.LoadDeviceByName("Oculus") launches the Oculus Desktop App here...
    :mad::mad::mad::mad::mad::mad: