Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by Sir-Gatlin · May 21, 2017 at 02:52 AM · vrcrashcodepage360-degrees

How to toggle VR (cardboard) on and off in 5.6

I am having the biggest issue with VRsettings.enable(). All the info I find seem to take place before the 5.6 patch and nothing seems to be working the way it is suppose to. real simple I need the first scene to be non vr and the second to be VR. I have tried all combinations to try and get this to work. I will have VR enabled with cardboard selected in Player settings. On launch I will call

 public IEnumerator startup()
     {
         VRSettings.LoadDeviceByName("none");
         yield return null;
         VRSettings.enabled = false;
     }

which the splash screen will be vr (another problem ill deal with later) but the scene will load non-vr. but when I load a new scene, then on start on the new scene I call (newDevice = cardboard)

 public IEnumerator LoadDevice(string newDevice)
     {
         VRSettings.LoadDeviceByName(newDevice);
         yield return null;
         VRSettings.enabled = true;

the scene will crash on android but work fine in editor. If i take out the Loaddevice stuff and just toggle VRSettings.enabledit will work the first time I build it to the phone, but will crash every time there after. Am I missing something? or is there an issue with this? did it change in 5.6? I have no idea. any help would be greatly appreciated!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
6
Best Answer

Answer by Liinnkk · May 23, 2017 at 11:03 PM

I answered a very similar question some days ago. There's some code you may find useful, so click here if you're insterested.

First, be aware that VR in Editor is just emulated by Google SDK, and VR in android is using Unity's Native Support, those are different things so the "if it works in editor it should work on android" logic will be not true. Keep it in mind.

If you want to start the game in Non-VR mode, configure your Player Settings like this: alt text It's important to set 'None' as the first element in your SDKs list, this way your game will start and run in Non-VR mode (even the splash screen) until you start it manually.

To start the VR manually at run-time, you should load the VR device and set VRSettings.enable true when device is already loaded. This is really important because if you read the documentation of LoadDeviceByName(), you'll notice that this command (quoting the docs) "loads the requested device at the beginning of the next frame. So if you set VRSettings.enable true right after call LoadDeviceByName(), it will not load correctly.

But your code is not wrong! You should only be careful if you're calling it correctly. Considering the IEnumerator and the yield, the right way to call it will be using a Coroutine:

 StartCoroutine(LoadDevice("cardboard"));

Hope it helps!

Oh! And one last thing: I strongly recommend you to download a newer version of Unity (try 2017.1 beta for now). That's because Unity 5.6 is using Google NDK 1.2, which has a known leak when you go in and out of VR.


vrconfig.png (4.4 kB)
Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Sir-Gatlin · Jun 03, 2017 at 11:32 PM 0
Share

awesome! the info you left at the last thread was exactly what I ended up using.

avatar image Morwin25 · Oct 16, 2017 at 08:27 PM 0
Share

Thank u! It is helpful.

avatar image AlClar1ty · Oct 16, 2017 at 09:04 PM 0
Share

Can i ask something... What if i want just to set the VR$$anonymous$$odeEnabled = false in GVR? Because in my case, when it's load device to "cardboards" it's always back to true. So i can go to mono mode VR...

avatar image Sir-Gatlin · Oct 17, 2017 at 02:25 PM 0
Share

Im guessing you are asking how to do $$anonymous$$agic Window. you will want to have VRsettings.enable = true, and LoadDeviceByName(none). This will keep the VR motion but have no special viewing device and will work as a magic window.

avatar image PandamoniumDev · Oct 27, 2017 at 05:14 PM 0
Share

thank you so much for this! I've been trying to figure out how to dynamically toggle Google VR (cardboard and daydream) along with standalone mode(mouse/keyboard input and/or touchscreen input) depending on which device is detected using Platform Dependent Compilation . I've had some obstacles with this since GVR likes to automatically start up components soemtimes even if you disable VR. For instance the reticle pointer still wants to instantiate even when I set LoadDeviceByName(none). Would it be better to disable all GVR objects by using tags? for instance, if I tag every gvr object with "GVR" then in my script set GameObject.FindObjectsWithTag("GVR").SetActive(false) ? What do you think is the best solution?

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

9 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

My VR game build crashes when the terrain is enabled. 0 Answers

VR game crashes 2 Answers

Access Violation Crash in Compiled VR game on projectile hit 1 Answer

Gear VR crash issue with unity 5.4.2 p2 0 Answers

Switching VR platforms via VRSettings 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges