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
0
Question by magnacartaelle · May 22, 2017 at 03:22 PM · c#vropengl

VRSettings.enabled sometimes not working.

Hi,

I'm having a bit of a confusion with toggling VR on and off in my project.

I have the following public function that toggles the VR mode on or off, depending on the user's action (i.e. clicking on a game object).

 public void toggleVR()
     {
         isVROn = !isVROn;
 
         if (isVROn)
         {
             Screen.orientation = ScreenOrientation.LandscapeLeft;
             StartCoroutine(LoadVRDevice("Cardboard",isVROn));
         }
         else
         {
             Screen.orientation = ScreenOrientation.Portrait;
             StartCoroutine(LoadVRDevice("None", isVROn));
         }
     }

and here is the coroutine that is called

 private IEnumerator LoadVRDevice (string device, bool enabled)
     {
         VRSettings.LoadDeviceByName(device);
         yield return null;
 
         if (!VRSettings.loadedDeviceName.Equals(device))
         {
             Debug.Log("Waiting extra frame");
             yield return null;
         }
 
         Debug.Log("Loaded device:" + VRSettings.loadedDeviceName);
 
         yield return null;
         VRSettings.enabled = enabled;
     }

This two functions work pretty alright, but I've encountered issues where the console will throw the following message when I attempt to enable VR:

OPENGL NATIVE PLUG-IN ERROR: GL_INVALID_OPERATION: Operation illegal in current stateUnityEngine.VR.VRSettings:set_enabled(Boolean)

It usually happens after I add some function/coroutine calls to other scripts which are called much earlier than the toggleVR method, and when it happens, my reticle no longer respond to objects.

So, my question is more to, what are the common causes for this error? Is my coroutine not working, or is it something else? Would really like to know what's going on cause it's been bugging me for days now :(

Just a heads up that am pretty new to Unity and VR, so what I've written may not be the best approach, but it's what I've gotten from searching around online and all.

Thanks in advance.

Comment
Add comment · Show 2
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 Liinnkk · May 22, 2017 at 05:08 PM 0
Share

I could not undestand why do you placed these yield returns in your coroutine. I mean, the only yield return needed in my opinion is the one after LoadDeviceByName(), since the device will only be called at the beginning of the next frame. The other calls seems pretty useless to me. Could you explain me that?

Well, try to simplify your LoadDeviceVR method to something like this:

 private IEnumerator LoadVRDevice (string device, bool enabled){
     VRSettings.LoadDeviceByName(device);
     yield return null;
     VRSettings.enabled = enabled;
 }

Tell me what happened.

avatar image magnacartaelle Liinnkk · May 23, 2017 at 04:55 AM 0
Share

Hi Liinnkk,

Well, I thought maybe there's a delay in loading the device, hence I added in the yields. I've not fully grasped the full understanding of yields but from reading around online, that's what I came up with, redundant maybe, but it kinda worked at that time.

Also, I tried simplifying the method as below:

 private IEnumerator LoadVRDevice (string device, bool enabled)
     {
         VRSettings.LoadDeviceByName(device);
         yield return null;

//I kept the debug here to see if it loads. Debug.Log("Loaded device:" + VRSettings.loadedDeviceName); VRSettings.enabled = enabled; }

but still no success :( What are the usual causes for this OpenGL error though? I don't quite get it. :(

Also, thanks for the response.

0 Replies

· Add your reply
  • Sort: 

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

7 People are following this question.

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

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Unity Arduino VR problem 1 Answer

Google Daydream Thread with Unity 1 Answer

Why doesn't my VR iron man flight system work? 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