Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 /
  • Help Room /
avatar image
0
Question by Spherea3D · May 25 at 06:40 PM · unityeditor

,I've the problem, that my app made with unity for Oculus Quest2 does'nt stop and resume, when I take off the VR-glasses. What am I missing? What do I need to set-?

I've the problem, that my app made with unity for Oculus Quest2 does'nt stop and resume, when I take off the VR-glasses. What am I missing? What do I need to set?

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

2 Replies

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

Answer by Spherea3D · May 26 at 08:40 AM

Thank you very much, @rh_galaxy. I am using Oculus integration unitypackage. Unfortunately your code is not working. Or maybe I copied it into the script wrong?

I used it in this way:

public class XRDevice { private static InputDevice headDevice; public XRDevice() { if (headDevice == null) { headDevice = InputDevices.GetDeviceAtXRNode(XRNode.Head); } }

 /// <summary>
 /// returns true if the HMD is mounted on the users head. Returns false if the current headset does not support this feature or if the HMD is not mounted.
 /// </summary>
 /// <returns></returns>
 public static bool IsHMDMounted()
 {
     if(headDevice == null || headDevice.isValid == false)
     {
         headDevice = InputDevices.GetDeviceAtXRNode(XRNode.Head); 
     }
     if (headDevice != null)
     {
         bool presenceFeatureSupported = headDevice.TryGetFeatureValue(CommonUsages.userPresence, out bool userPresent);
         if (headDevice.isValid && presenceFeatureSupported)
         {
             return userPresent;
         }
         else
         {
             return false;
         }
     } else
     {
         return false;
     }
 }

}

Comment
Add comment · Show 3 · 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 rh_galaxy · May 26 at 08:55 AM 0
Share

Is it compiling? What version of Unity do you use? But if you use Oculus.Platform maybe you can use this?

 OVRPlugin.userPresent
avatar image Spherea3D rh_galaxy · May 31 at 10:34 AM 0
Share

Sorry, but I'm quite newbe. How can I use OVRPlugin.userPresent? I'm using Unity 21.2.18 It is still compiling... Thanks!

avatar image rh_galaxy Spherea3D · May 31 at 10:50 AM 0
Share

By adding this at the top of the file...

 using Oculus.Platform;

That is available since you say you use Oculus integration.

avatar image
0

Answer by rh_galaxy · May 25 at 06:53 PM

It depends if you use new or old way with plugins and/or Oculus Integration unitypackage. Remember that no audio or input other than to unpause should be possible. You need to do the actual pause your self. This works for me (in my GameManager that always runs)...

 using UnityEngine.XR;
 using Oculus.Platform;
 
 bool bPause = false;
 void Update()
 {
     //get user present this way
     UnityEngine.XR.InputDevice headDevice = InputDevices.GetDeviceAtXRNode(XRNode.Head);
     bool presenceFeatureSupported = headDevice.TryGetFeatureValue(
         UnityEngine.XR.CommonUsages.userPresence, out bool userPresent);
 
     //also pause if in oculus home universal menu
     bool bPauseNow = (!OVRPlugin.hasInputFocus || !OVRPlugin.hasVrFocus) || !userPresent);
 
     //pause state change
     if (bPause != bPauseNow)
     {
         bPause = bPauseNow;
         if (bPauseNow)
         {
             Time.timeScale = 0.0f; //stops FixedUpdate
             AudioListener.pause = true; //also need to stop all sound
         }
         else
         {
             Time.timeScale = 1.0f;
             AudioListener.pause = false;
         }
     }
     if(bPause) return; //prevent other input from below
     
     //...
 }
Comment
Add comment · 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

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

190 People are following this question.

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

Related Questions

how to get component of array in unity 0 Answers

"Failed to load window layout" Error 5 Answers

Unity installation error, DISM 87 0 Answers

3D grid tetris game problem! 0 Answers

unity crashes while importing large 3Dmodel file 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