Search Unity

Unity 5.6.0f3 Native GVR Android / iOS enabling and disabling VR

Discussion in 'AR/VR (XR) Discussion' started by MaskedMouse, Apr 4, 2017.

  1. MaskedMouse

    MaskedMouse

    Joined:
    Jul 8, 2014
    Posts:
    1,092
    [Unity 5.6.0f3 + Gvr SDK v1.30]

    So far the Google VR SDK is just frustrating to work with.
    Even with Native SDK support in Unity 5.6 you still need the GVR SDK package implemented to be able to use the reticle pointer.
    GvrViewer.VREnabled doesn't work with native implementation so when it is an Android build / iOS build it requires to set VRSettings.Enabled

    We have an app in development where the user should be able to engage into VR mode when the user wants to like clicking on a button.
    When the user presses the X at the left top as he/she wants to exit VR mode, we as developers want to tell it to close the VR Mode by setting VRSettings.Enabled = false.
    Though the native integration is closing the app no matter what. We have no control of what the X is supposed to do.
    Even an Application.CancelQuit() call doesn't work to cancel the quitting.
    We can't seem to handle the event the X button gives us.
    So we can get in to VR whenever we want, just not get out of it.

    Is there a solution for this that we're not aware of?
     
  2. Cascho01

    Cascho01

    Joined:
    Mar 19, 2010
    Posts:
    1,347
    Absolutely the same for me. So, bookmarked......

    EDIT:

    Meanwhile I was able to start my app in a non vr-mode and to switch to cardboard-mode without any additional plugins:

    https://docs.unity3d.com/Manual/VROverview.html#EnablingVRSupport

    So after adding "None" to Virtual Reality SDKs on position 0 and "Cardboard" to position 1, following script allows at least to enable cardboard:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.VR;
    5.  
    6.  
    7. public class EnableVR : MonoBehaviour {
    8.  
    9.  
    10.     public string[] devices;
    11.  
    12.  
    13.     void Awake () {
    14.  
    15.         devices = VRSettings.supportedDevices;
    16.     }
    17.  
    18.  
    19.     public void Enable_VR (bool isEnabled) {
    20.  
    21.         if (isEnabled)
    22.             StartCoroutine("LoadVRDevice");
    23.         else
    24.             StartCoroutine("LoadStandardDevice");
    25.  
    26.     }
    27.  
    28.  
    29.     IEnumerator LoadStandardDevice()
    30.     {
    31.         VRSettings.LoadDeviceByName(devices[0]);
    32.         yield return null;
    33.         VRSettings.enabled = false;
    34.     }
    35.  
    36.  
    37.     IEnumerator LoadVRDevice()
    38.     {
    39.         VRSettings.LoadDeviceByName(devices[1]);
    40.         yield return null;
    41.         VRSettings.enabled = true;
    42.     }
    43. }
    44.  

    Now the question is:

    How to get the cardboard X not to close the app but to call "Enable_VR(false)"?
    Or - How to completely disable that X (and use a custom button instead)?
     
    Last edited: Apr 4, 2017
  3. Adamcbrz

    Adamcbrz

    Joined:
    Jul 13, 2011
    Posts:
    21
    I am suffering through the same issue. On the google vr android sdk there is a method setCloseButtonListener that allows you to override that method but can't figure out how to do it within unity. Is there a way to access the underlining implementation of google vr? Can you use the VRDevice.NativePtr to access it from native code?

    Along side of that is there an easy way to determine if daydream is supported? Because if you implement @Cascho01 process of switching from None to cardboard then you wouldn't have support for daydream. And it seems that if you try setting it to daydream it just fails with a log saying it isn't supported and doesn't fall back to cardboard.
     
  4. batchku

    batchku

    Joined:
    Oct 27, 2014
    Posts:
    4
    Also struggling with the same issue. Perhaps at an even more fundamental level:

    With Unity 5.6f3 and gvr-unity-sdk v.1.30, here is my process and problems:
    • Open Unity 5.6f3; create a new project
    • Assets > Import Package... > Custom Package.... and select "GoogleVRForUnity.unitypackage"
    • Import everything
    • Change player settings to enable "Virtual Reality Supported"
    • add "Cardboard" under "
    • Open this scene "GoogleVR>Demos>Scenes>GVRDemo"; press Play in Unity
    Problems:
    • I get an error in the game window that says To use the controller, please upgrade to a version of Unity with the GVR native integration. Isnt Unity 5.6f3 the latest version and doesn't it have native GVR integration?
    • I'm not able to move around with the mouse; shouldn't I be able to do that, for CardBoard?
     
    SunnyChow and HenryAsh like this.
  5. MaskedMouse

    MaskedMouse

    Joined:
    Jul 8, 2014
    Posts:
    1,092
    bumping this thread, hoping that one of the Unity Developers could shed some light on this.
     
  6. SiliconDroid

    SiliconDroid

    Joined:
    Feb 20, 2017
    Posts:
    302
    Bump... I want this also.
     
  7. headlessstudio

    headlessstudio

    Joined:
    Feb 25, 2016
    Posts:
    83
    Same here, also looking for a way to change the default behaviour of the X button in the native integration of cardboard mode. *bumping*
     
  8. eyalfx

    eyalfx

    Joined:
    Oct 8, 2010
    Posts:
    108
    There are 2 or 3 other threads with the exact same question. So I may as well add myself to this one too.
    The short answer is that currently there is no way to developers to use the X button that shows up when in VR mode. We need to implement a button in the vr view (3d view) to exit vr mode. Hopefully that will change back to what it used to be , which is full control over what the app does when a user press the X button
     
  9. andyz

    andyz

    Joined:
    Jan 5, 2010
    Posts:
    2,269
    We used 5.5.1 and GVR 1.4 to allow going into and out of VR - too many bugs with the 5.6 native approach.
    However that X button appears to do nothing at all so don't know why it even appears
     
  10. AteoMarcel

    AteoMarcel

    Joined:
    Jan 5, 2017
    Posts:
    17
    It is still possible to get the non native Google VR version to run:

    1. Find in all files (in monodevelop or visual studio or another editor) " UNITY_HAS_GOOGLEVR " (without ") and replace it with "SCREW_YOU". (or any other tag you are not using)
    2. find the text "UNITY_5_6" in the file GvrBuildProcessor and replace it as well with "SCREW_YOU"
    3. find the line "scale *= 2.0f; " and delete it (or replace it a comment like "//DO NOT DESTROY MY PERFORMANCE")
    4. Find the files "GVRBackwardsCompatibility.unitypackage" and "GVRiOSNativeCompatibility" in the folder GoogleVR in the unity project and double click them (and press yes on import)
    5. Change the player settings. Virtual Reality Supported has to be set to FALSE (no cross)
    6. Also in the player settings put "Multithreaded Rendering" to off. (You can try graphics jobs experimental if you want instead).
    7. restart unity
    8. if building for IOS copy paste the files "CardboardSDK.bundle", "GoogleKitCore.bundle", "GoogleKitDialogs.bundle", "GoogleKitHUD.bundle" and "MaterialRobotoFontLoader.bundle" from an unity 5.5 project into yours.
    You can find them under Plugins/iOS (and put them into that folder in the new Unity Version).

    After this you are able to build using the google cardboard sdk 1.4 under Unity 5.6
     
  11. xipeluife

    xipeluife

    Joined:
    Jan 15, 2013
    Posts:
    14
    Can confirm this works on Android. You are a lifesaver! Hopefully, these errors are soon fixed on the next patches. (I had the same errors in Unity 5.6.1f1).

    I will test this on iOS and report back.
     
  12. shakhruz

    shakhruz

    Joined:
    Feb 17, 2011
    Posts:
    43
    Thank you AteoMarcel, it worked for me too...
     
  13. jjennings1990

    jjennings1990

    Joined:
    Oct 25, 2012
    Posts:
    132

    This is very helpful . Is there any way to use GVR 1.4 with unity 5.6 and still make use of the daydream controller ?
     
  14. AteoMarcel

    AteoMarcel

    Joined:
    Jan 5, 2017
    Posts:
    17
    Sorry I do not really know about that.
     
  15. walidabazo

    walidabazo

    Joined:
    Jul 8, 2017
    Posts:
    17