Search Unity

How do you get SteamVR headsetOnHead to see if the headset is already on when the scene is started

Discussion in 'VR' started by Giantbean, May 3, 2019.

  1. Giantbean

    Giantbean

    Joined:
    Dec 13, 2012
    Posts:
    144
    Looking at SteamVR.cs and Play.cs in the Steam VR 2.2 plugin I can set the game to pause when the headset is taken off however if the play button is pressed while the headset is already on it fails to get the up or down state of the HMD sensor?

    Code (CSharp):
    1. using UnityEngine;
    2. using Valve.VR;
    3.  
    4. public class StepRequirement_headsetOn : MonoBehaviour
    5. {
    6.  
    7.     public bool hmdOn;
    8.  
    9.  
    10.     [Tooltip("This action lets you know when the player has placed the headset on their head")]
    11.     public SteamVR_Action_Boolean headsetOnHead = SteamVR_Input.GetBooleanAction("HeadsetOnHead");
    12.  
    13.     private void Start()
    14.     {
    15.         //Let the scene know if the headset was already on when loaded.
    16.  
    17. //???
    18.  
    19.     }
    20.  
    21.     void Update()
    22.     {
    23.         if (SteamVR.initializedState != SteamVR.InitializedStates.InitializeSuccess)
    24.             return;
    25.  
    26.         if (headsetOnHead != null)
    27.         {
    28.  
    29.             if (headsetOnHead.GetStateDown(SteamVR_Input_Sources.Head))
    30.             {
    31.                 //Debug.Log("<b>SteamVR Interaction System</b> HMD on head");
    32.                 hmdOn = true;
    33.                 //Unpause
    34.                 if (Time.timeScale == 0)
    35.                     Time.timeScale = 1;
    36.  
    37.             }
    38.  
    39.             else if (headsetOnHead.GetStateUp(SteamVR_Input_Sources.Head))
    40.             {
    41.                 //Debug.Log("<b>SteamVR Interaction System</b> HMD off head");
    42.                 hmdOn = false;
    43.                 //Pause?
    44.                 if (Time.timeScale == 1)
    45.                     Time.timeScale = 0;
    46.             }
    47.  
    48.         }
    49.  
    50.     }
    51. }
    I can pause the time on start however if the headset is already on when the scene starts then it never un-pauses. So how do you get the state from this sensor if there is no change when initialized?


    P.S. Can someone explain tags on the forum. I try to add tags like VR, HMD, and the like but it never lets me tag as it says I can not create new tags while failing to show a list of available tags to use?
     
    kirillrybin likes this.
  2. dev_reimu

    dev_reimu

    Joined:
    Jun 24, 2017
    Posts:
    10
    I'm facing the same issue. Considering how old this thread is, have you found a solution?
     
  3. Giantbean

    Giantbean

    Joined:
    Dec 13, 2012
    Posts:
    144
    I don't even remember this issue anymore. I think I just removed this and haven't used the feature since?
     
  4. dev_reimu

    dev_reimu

    Joined:
    Jun 24, 2017
    Posts:
    10
    Same, I just decided on a better system in the end.