Search Unity

unity 5.6 cardboard - how to use back button for a custom action

Discussion in 'AR/VR (XR) Discussion' started by eyalfx, Apr 17, 2017.

  1. eyalfx

    eyalfx

    Joined:
    Oct 8, 2010
    Posts:
    108
    I've been trying to use the Cardboard back button (on screen , top left x) to exit VR mode. Before the native unity integration (5.5) I was able to just use gvrViewer.BackButtonPressed but this doesn't seem to work now.
    I've also tried if (Input.GetKeyDown(KeyCode.Escape)) but the app still exits.
    So I'm added a Input.backButtonLeavesApp = false; but it doesn't seem to help.
    When I press the button the app exits to select new apps and just runs in background.
    Any ideas?
    Thanks.
     
    isostopy likes this.
  2. joejo

    joejo

    Unity Technologies

    Joined:
    May 26, 2016
    Posts:
    958
    I believe you can customize what happens by handling KeyCode.Escape, but you can't stop the app from closing.
     
  3. eyalfx

    eyalfx

    Joined:
    Oct 8, 2010
    Posts:
    108
    That's too bad. It used to work perfectly with the google sdk in older versions of Unity. If you want to make an app that has both VR and nonVR modes , this is the most logical button to use to exit VR mode. Hopefully it will be fixed in future releases.
    Thanks for clarifying.
     
  4. isostopy

    isostopy

    Joined:
    Dec 19, 2016
    Posts:
    6
    Hi! I have an issue in the same way.

    Using VR Cardboard package I used to create a button in UI - Screen Space Overlay to exit VR which was over the stereoscopic split screen, but with the new native cardboard SDK in Unity 5.6, the button is hidden by the split screen. In spite of this, the button works but is hidden. I'm working to find a solution.
     

    Attached Files:

  5. joejo

    joejo

    Unity Technologies

    Joined:
    May 26, 2016
    Posts:
    958
    I believe the recommended way to do what you want is to provide a button in the scene that the user can select from within VR that will notify you to switch the current VR device to None, and visa-versa.
     
  6. mira_leung

    mira_leung

    Official Google Employee

    Joined:
    May 17, 2016
    Posts:
    70
    You can check for Input.GetKeyDown(KeyCode.Escape) in Update() and perform the desired action there. That's how we close the app in the demo scenes - please see Assets/GoogleVR/Demos/Scripts/DemoInputManager.cs.

    GvrViewer.cs source does not execute on-device in the native integration, and we will be removing support for Unity versions older than 5.6 in an upcoming release.
     
  7. isostopy

    isostopy

    Joined:
    Dec 19, 2016
    Posts:
    6
    Thanks for your reply!
     
  8. eyalfx

    eyalfx

    Joined:
    Oct 8, 2010
    Posts:
    108
    Yes, we handle it like that in our app. Just wanted to give the user another option to quickly navigate back and forth if they are not in the VR headset.

    Also good to know about the GvrViewer.cs not being executed on device. Now it starting to make sense. I just hope we will get Unity Native integration to the following featured:
    GvrViewer.triggerd - is there an Input.GetkeyDown() equivalent to this?
    GvrViewer.titlted
    GvrViewer.backButtonPressed.
    Thanks
     
  9. Tom-Goethals

    Tom-Goethals

    Joined:
    Mar 6, 2015
    Posts:
    102
    I have the same request
    To me it would make more sense for the x button top left in the native cardboard integration to just send an escape event for the developer to take care off. Any workarround for the exit behavior right now in Unity 5.6.0f3?
    Thanks!
     
  10. eyalfx

    eyalfx

    Joined:
    Oct 8, 2010
    Posts:
    108
    I second that. It's how it worked before and it was awesome!
     
  11. mattSydney

    mattSydney

    Joined:
    Nov 10, 2011
    Posts:
    171
    I can confirm that in iOS Input.GetKeyDown (KeyCode.Escape) will capture the back button event. Beware though if you Load a scene immediately when in VR mode it will crash the app. This is a separate bug.

    Solution:
    public void Update(){
    if (Input.GetKeyDown (KeyCode.Escape)) {
    StartCoroutine (VROff ());
    }
    }

    public IEnumerator VROff () {
    VRSettings.LoadDeviceByName ("None");
    yield return null;
    VRSettings.enabled = false;
    Debug.Log ("Disable VR");

    SceneManager.LoadScene("Your Scene", LoadSceneMode.Single);
    }
     
  12. AteoMarcel

    AteoMarcel

    Joined:
    Jan 5, 2017
    Posts:
    17
  13. Tom-Goethals

    Tom-Goethals

    Joined:
    Mar 6, 2015
    Posts:
    102
    Confirming also that in iOs it works as expected. instead of a close button there you get a back arrow. That makes more sense to the app we're building. (fingers crossed for a fix for android soon)
    Anybody posted a bugreport were i can vote yet? can't seem to find one.
     
  14. mattSydney

    mattSydney

    Joined:
    Nov 10, 2011
    Posts:
    171
    I have rolled back to 5.5 as there is an issue with integrated cardboard in iOS, with rendering
     
  15. Kubic75

    Kubic75

    Joined:
    Jan 2, 2017
    Posts:
    83
    Any news on getting rid of the back arrow and the gear icon in cardboard view (Unity2017)?
     
    cream03 and codestage like this.
  16. codestage

    codestage

    Joined:
    Jul 27, 2012
    Posts:
    1,931
    Hey, @Kubic75 !

    Did you managed to figure out this?