Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Unity5.6.0f3, Unity Native Cardboard: How to add an onscreen button for enable/disable vr mode?

Discussion in 'AR/VR (XR) Discussion' started by cdytoby, Apr 6, 2017.

  1. cdytoby

    cdytoby

    Joined:
    Nov 19, 2014
    Posts:
    181
    I was still using unity googlevr sdk 0.8.1 because that is the only version that I can customize Cardboard UI element.

    Now I just tried newest Unity 5.6.0, and also removed all cardboard sdk related files in the project,
    and now i have this problem:

    How to add an screen overlay ui when in the vr mode?

    Because I had an custom ui overlay, so that I can enable/disable cardboard view whenever I want.
    And now I don't know how to do it, because ui overlay won't show on screen.

    And I need more information about the following:
    1. Does VRSettings.enabled also works for native unity cardboard and daydream? GearVR too?
    2. If I enabled all vr mode, like cardboard/daydream/gearVR, if I deployed it on a device that support those, can I use them all at same time? For example switch between cardboard mode/daydream mode/ gearvr mode.
     
    Last edited: Apr 6, 2017
  2. pozil

    pozil

    Joined:
    Apr 6, 2017
    Posts:
    2
    Hi,

    I have a similar problem.

    I had a project running with Google VR SDK 0.9.1 under Unity 5.4.2
    I used to toggle VR mode on and off programmatically (my app had a login screen before entering VR mode) and it worked fine.

    Now with the latest Google VR SDK 1.30.0 and Unity 5.6.0f3, toggling VR mode no longer works.
    When entering VR mode, I get a full black screen.
    I seems that the native VR support of Unity 5.6.x disables the ability to toggle VR mode as per the code documentation (see screenshot).

    Can someone from Unity or Google confirm this?
    Is there an alternative to toggle VR mode?

    Cheers,
     

    Attached Files:

  3. mira_leung

    mira_leung

    Official Google Employee

    Joined:
    May 17, 2016
    Posts:
    70
    GvrViewer source does not run on-device in Unity 5.6 - please use a combo of VRSettings.enabled, VRSettings.loadedDevice, and LoadDeviceByName. The GVR device names are "cardboard" and "daydream", all lowercase.

    @cdytoby What is your use case for customizing the UI layer? This is now controlled from VrCore, for UX reasons.

    We recommend updating to Unity 5.6.0f3 and v1.40 of the GVR Unity SDK when it is released, because we will no longer support Unity versions older than 5.6 as of v1.50.
     
  4. cdytoby

    cdytoby

    Joined:
    Nov 19, 2014
    Posts:
    181
    Wow, Official Google Employee? Thanks for the reply, I'll state our full requirements here.

    1. We need a vr mode and non-vr mode switch button, so In former version I added Screen Overlay Canvas in Unity, and added a button at bottom right to switch both modes.
    In order to make button click work, I customized the input module, modified from cardboard sdk, I also took some codes from unity ui source code which are open sources in bitbucket.
    2. The back button on the top left side must hide. We have our own methods to handle back button.
    In non-vr mode, we have some action buttons on the top left side.
    In vr mode, we have world canvas ui that contains the same set of the action buttons.
    3. We need to play 3D videos in the app. That means left eye and right eye should be able to display different contents. Now Unity Camera can also do this, so this shouldn't be a problem.
    4. iOS cardboard support. Last time we checked, there is an issue on transition screen or something when the ios device is not in landscape state, and there are also issues when user switch from non-vr to vr, vr view is shrinked. I don't know if the unity 5.6 have the same issue. But it was there in cardboard sdk around 1.1 version.
    5. The most perfect awesome thing would be: user can switch from one to another including non-vr mode, cardboard-vr mode, daydream-vr mode, and gear-vr mode, if the android device supports it. (It may be too hard, so it's not important right now.)

    It would be great if Unity official or google official can provide some more information on this.
     
    Last edited: Apr 11, 2017
    Cascho01 likes this.
  5. Cascho01

    Cascho01

    Joined:
    Mar 19, 2010
    Posts:
    1,347
    When our App provides both Non-VR-Mode and VR-Mode and we can switch between these modes it is not neccessary that the app starts in Landscape-Mode. So:

    6. When we enable "Virtual Reality Supported" in the PlayerSettings the App is forced to start in LandscapeLeft-mode.
    Please remove this, too. (It gets handled when we enable VR-Mode.)
     
  6. Cmoche

    Cmoche

    Joined:
    Jan 10, 2016
    Posts:
    4
    Adding developer backing on these
    "1. We need a vr mode and non-vr mode switch button, so In former version I added Screen Overlay Canvas in Unity, and added a button at bottom right to switch both modes.
    In order to make button click work, I customized the input module, modified from cardboard sdk,
    2. The back button on the top left side must hide. We have our own methods to handle back button.
    In non-vr mode, we have some action buttons on the top left side.
    In vr mode, we have world canvas ui that contains the same set of the action buttons."

    Haven't stepped up to 5.6/1.4 for our product yet due to these limitations. I understand Google's desire to maintain a certain level of Quality on the UX, but removing customization from developers is not the way to do it.

    Presently migrating from 5.5/1.2 up to 5.6/1.4 'breaks' our applications ability to start in non VR mode, call VRSettings from 2D screen (settings, req'd privacy notice, etc) to starting VR mode (VRSettings.enabled, and etc) app dumps after completion of VR loading. Forcing users to complete all settings and notices inside VR mode...

    Google, can we bring back the back end customizations for Developers. Honest, we know (mostly) what we're doing, don't go all Apple on us...
     
    casey945 and cdytoby like this.
  7. CogumeloSoft

    CogumeloSoft

    Joined:
    Dec 28, 2012
    Posts:
    86
    About allow us to darken/hide/remove those buttons from the UI (That do nothing other than cause problems ) there was a lot of complains about it in the github and they just ignored it.
    https://github.com/googlevr/gvr-unity-sdk/issues/266
    They said that people are not capable to exit the app without it (Makes no sense at all). See also that the HMD configuration will be done once (first time when you get a new headset) but it icon is mandatory in all your apps, all the time! Great UX design google have for it don't you think?
    Hope someday they take sometime to listen the developers a bit more.
     
    casey945 and cdytoby like this.
  8. Cmoche

    Cmoche

    Joined:
    Jan 10, 2016
    Posts:
    4
    Making an internal button assigned to Application.Quit seems to have worked for the past 5 years or so for the rest of the development world, across just about every platform.....

    And Google "If an application hangs preventing the user from using internal controls" this will also lock up your on screen UI as well. In which case, the user is going to Have to touch the device... This isn't a difficult concept
     
  9. eyalfx

    eyalfx

    Joined:
    Oct 8, 2010
    Posts:
    108
    We also need to start the app in Non-VR mode which we had in previous Unity version. Now in 5.6 is starts in VR mode , then we immediately switch back to non-VR mode and that looks getho
     
    casey945 likes this.
  10. mattSydney

    mattSydney

    Joined:
    Nov 10, 2011
    Posts:
    171
    Have you tried adding "None" as the first element in VR settings in the player? That might do the trick
     
  11. kor

    kor

    Joined:
    Oct 29, 2009
    Posts:
    122
    I've also been trying to setup "an onscreen button for enable/disable vr mode".

    Using 5.6.0f3 and GVR v1.40 on a Note4: if I "VRSettings.LoadDeviceByName("");" and/or "VRSettings.enabled = false;" the gyro just returns 0.0.0 from both Unity VR and GVR (InputTracking.GetLocalRotation and GvrController.Gyro) so I cannot rotate the camera view in non-VR mode.

    This https://github.com/googlevr/gvr-unity-sdk/issues/532 didn't work for me due to the above paragraph.


    Even started looking init setting it up with "Camera.main.transform.Rotate(-Input.gyro.rotationRateUnbiased.x, -Input.gyro.rotationRateUnbiased.y, 0)" but that is drift-ey... -_-.

    Open to any advice.

    Edit: I guess I'll try downgrading Unity/gvr today...

    @mattSydney that does work, but from my experience when in the "None" VR mode both Unity VR and GVR (InputTracking.GetLocalRotation and GvrController.Gyro) just return 0.0.0.
     
    Last edited: May 6, 2017
  12. ProudLittlePinwheel

    ProudLittlePinwheel

    Joined:
    Feb 6, 2014
    Posts:
    8
    Quite frankly I'm extremely dissapointed with the 'not so thought through or tested' native integration of the Google VR in 5.6. We've had nothing but problems. I know that with Unity 5.5 and GVR Unity SDK v1.40 we had none of the problems in 5.6, namely we could:-
    • Go into and out of VR as many times as we want, no problem, no crashes, no weird screen warping.
    • Overlay UI over the top of the Cardboard UI (no longer an option as per this thread)
    We are running a super simple test app on a Samsung S6 running Android 6.0.1 and with Unity 5.6 native integration it crashes every time you re-enter VR after the first time you use it (and sometimes even on the first time) plus it warps the screen in a weird way after exiting VR the first time back into the app.

    I filed a bug report but Unity literally just said it was a duplicate of an existing bug which has been present since Unity 5.4 and still is not fixed (https://issuetracker.unity3d.com/is...out-of-memory-problems-and-rendering-slowdown).
    Can't really trust that though since the issue only occurs when using the 'native' integration present in 5.6.

    All in all just a really poor experience, going from a perfectly working version in Unity 5.5 to a completely broken version in Unity 5.6! :(
     
  13. kor

    kor

    Joined:
    Oct 29, 2009
    Posts:
    122
    I ended up manually implementing Gyro navigation properly after calling "VRSettings.LoadDeviceByName("");" and "VRSettings.enabled = false;" and I am experiencing the same issues you identify @ProudLittlePinwheel.
    1. Screen aspect is warped once VR is disabled.
    2. Going from VR to non-VR back to VR consistently crashes the app.
    3. GUI overlay doesn't work in VR mode.
    I'll try Unity 5.5 shortly as you mentioned you have had no problems with this. Thanks!
     
    Mistabullit likes this.
  14. mattSydney

    mattSydney

    Joined:
    Nov 10, 2011
    Posts:
    171
    One thing I noticed is that if I set VR enabled/Disabled in the same scene it didn't crash the device (iOS), but if, for example I had VR enabled, loaded a new scene and set VR disabled it crashed the device.

    Very frustrating. I never upgrade to new version of Unity until its been out a few months because it is always bug ridden. But I required the Video Player component in 5.6, it's been hell :(. 20 % dev, 80% f**cking around with bugs
     
  15. Mistabullit

    Mistabullit

    Joined:
    Aug 14, 2015
    Posts:
    7
    Hello Mira Leung,

    Thanks for the update on how to tackle this.

    //// Ranty bit
    Tiny Bit of Background: Mono is quite easy to use for those without Cardboard or other HMDs who are accustomed to holding a phone in front of them when using AR/360 video. It's also necessary to have as a mode for any mobile VR application, in my humble opinion. When I can't perform this switchl it is akin to denying users the audio in your product because they did not have headphones, sure the experience might not be as rich, but who remembers to take their cardboard with them everyday?I have a few experiments on the store and the users do use the mono view. Sure mono may (for now) deny mobile users of a friend hand for an additional peripheral, but the current mobile VR user space has not matured completely to embrace these, so the min spec is gaze focused, with one button input (which can be detected also by tapping the screen).
    ///End rant


    But that small rant aside. I formerly used this simple script to switch between Stereo VR and Mono Window Mode and it worked amazingly well.

    GvrViewer.Instance.VRModeEnabled = !GvrViewer.Instance.VRModeEnabled;

    I followed your example in order to get this to work on 5.6 with the 1.4 package installed. A few quick notes:

    Here are the links to the calls mentioned above
    VRSettings.enabled
    VRSettings.supportedDevices (loadedDevice is now obsolete)
    VRSettings.LoadDeviceByName

    Sadly, when you call this as a toggle:
    VRSettings.enabled = !VRSettings.enabled;

    It is turning off all VR support for the device now, including movement tracking. Not switching the video mode that the GVRviewer used to handle quite elegantly. The Mono view is also quite badly skewed. I think in order to get the functionality back I will have to somehow replicate the switch that was used in the old GVRviewer when the player switches modes. :)

    The other reason I still put the GVRviewer in the editor for a scene is the nice "Hold Alt" to move your head around functionality. I have not found the equivalent for head movement without this with Unity's standalone solution, maybe someone else has.

     
  16. kor

    kor

    Joined:
    Oct 29, 2009
    Posts:
    122
    I am experiencing the exact same results in 5.6 as you @Mistabullit - do let me know if you get a solution working.

    I replied earlier but it was lost with Unity's forum hack roll-back.

    5.5 worked successfully as expected (thanks @ProudLittlePinwheel), where as 5.6 is broken for the transition from VR-mode to non-VR-360-mode aka "Magic Window" aka "Mono view" with Cardboard VR support.
     
    Last edited: May 6, 2017
    Mistabullit likes this.
  17. AteoMarcel

    AteoMarcel

    Joined:
    Jan 5, 2017
    Posts:
    17
    Any solution for this? We just are experiencing the same and it is really frustrating...
     
  18. mattSydney

    mattSydney

    Joined:
    Nov 10, 2011
    Posts:
    171
    I use this script (attached) to emulate head movement in the editor, it isn't perfect. Sorry to the original writer of the script I forget where it came from.

    Just drop onto your camera I set hold alt and mouse to move and CTRL to roll. You can set the options on the script
     

    Attached Files:

    Mistabullit and kor like this.
  19. kor

    kor

    Joined:
    Oct 29, 2009
    Posts:
    122
    Thanks for the script @mattSydney - is exactly what @Mistabullit was asking for.
     
  20. AteoMarcel

    AteoMarcel

    Joined:
    Jan 5, 2017
    Posts:
    17
    xipeluife and Mistabullit like this.
  21. casey945

    casey945

    Joined:
    Feb 16, 2009
    Posts:
    46
    One thing I noticed is that if I set VR enabled/Disabled in the same scene it didn't crash the device, but if, for example I had VR enabled, loaded a new scene and set VR disabled it crashed the device.
     
  22. Mistabullit

    Mistabullit

    Joined:
    Aug 14, 2015
    Posts:
    7
    Thanks for the script @mattSydney, nearly works perfectly. However there are a few of my UI elements that are in the world that now move with the camera that did not used to. I think I will stick with the GvrViewerMain in the scene for now as this solution is working without dragging those elements of the UI with it. It is fine whilst I'm editing and it's easy enough to delete/disable it before building. Now back onto the other part of the problem. :)
     
  23. Mistabullit

    Mistabullit

    Joined:
    Aug 14, 2015
    Posts:
    7
    GvrHead attached to the camera may help some people having this issue depending on how you have set up your scene.

    Check out the thread on GIT.

    This has not worked for my current experiment as I am following the Unity guide on setting up VR, and it thus it would require some rework.. It would be nice if one of the demos included in the asset package for GVR 1.5 was implemented using the native method and had this toggle working. You may note that if you attach a toggle script to the buttons on the floor canvas in the GVRTestScene, you will find it works. The view is horribly skewed and if you toggle two or three times you will notice the game crashes.



    This does not work for my current experiment as I'm attempting a new project with a native implementation of GVR using 5.6's instructions.

    I thought I might share this as there are people approaching GVR development from two angles now on 5.6 now.

    Unity Native--> I've built my project using the unity examples. This seems to have the most compatibility problems and lacks some of the older functionality of GVR. I will keep going to try and get a solution for this toggle. I will attempt a camera swap to see if that works. Not sure how I will do this, but if I can just switch to a different camera it will solve a bunch of things quickly.

    GVR / Native light --> This relies on using the GVRDemo as a point of reference and building your game from there. There is more work involved if you ever want to port your game because you will need to implement cameras and other things when the time comes.
     
  24. xipeluife

    xipeluife

    Joined:
    Jan 15, 2013
    Posts:
    14
  25. Mistabullit

    Mistabullit

    Joined:
    Aug 14, 2015
    Posts:
    7
    Yes,

    I find that setting it up with this is actually putting my camera out of place. Maybe others are not seeing the same issues.
     
  26. cdytoby

    cdytoby

    Joined:
    Nov 19, 2014
    Posts:
    181
    Is there any news on this? the app crashed when set VRSetting enable to false, and set VRDevice to None.

    I'm looking at the native java code in JD, and I saw a class called GoogleVR. How can I retrieve the object in Unity?
     
  27. apreasher

    apreasher

    Joined:
    Mar 30, 2017
    Posts:
    9
    My solution is to revert back to 5.5 and it works fine.
     
  28. kor

    kor

    Joined:
    Oct 29, 2009
    Posts:
    122
    @cdytoby This was my solution for toggling VR on and off in 5.6 and 2017 VrModeSwitch.cs. Not great but it works. Open to improvements.

    "I ended up needing to use Unity 2017.1.b8 for iOS building as that version fixed the weird skewed rendering issue on iOS builds. However when I installed 2017.1.b8 on Windows (instead of OSX - the video player never worked when I tried to build for iOS from Windows) it "upgraded" "Android: Apk files are now signed using the new APK Signature Scheme v2" which for me caused Google Play and Oculus to reject the apk. I stuck with 5.6.1p2 on Windows for Android Cardboard and Oculus Gear VR builds, but suspect 5.6.1p3 would be fine. Here was the matrix of bugs and different version I ran into for interest.

    I used this script for gyro camera in "magic window" (non-VR-360-mode) GyroCamera.cs. I wanted screen swiping to offset the camera like the JauntVR app in this mode but couldn't work it out xD.

    I could not revert back to 5.5 like @apreasher as I wanted to use the 5.6 Video Player.

    For me the "VrModeSwitch" script works fine switching from non-VR to VR and then back, but if you keep switching VR on and off the app fairly consistently crashes.
     
    Last edited: Jun 15, 2017
  29. Ivanicki

    Ivanicki

    Joined:
    Nov 15, 2017
    Posts:
    1
    Please help. The game on android for cardboard. When I set to an object script for example destroy and in the ivent trigger use pointer enter it works. But when I use pointer down , it doesn't work . Why can that be? I use unity 5.6 and googleVrForUnity_1.100.1.