Search Unity

SteamVR - ProximitySensor?

Discussion in 'AR/VR (XR) Discussion' started by dmennenoh, Oct 26, 2018.

  1. dmennenoh

    dmennenoh

    Joined:
    Jul 1, 2015
    Posts:
    379
    I found some code to poll the proximity sensor, to know when the HMD is on/off. However I am unsure how to implement - I keep getting the error that the proximity sensor action is not defined in default in actions. Here's the code:


    Code (CSharp):
    1.  SteamVR_Input_Sources m_inputSourceDevice = SteamVR_Input_Sources.Any;
    2.  
    3.         if (!isHeadsetOn && SteamVR_Input._default.inActions.Proximity_Sensor.GetState(m_inputSourceDevice))
    4.         {
    5.             Debug.Log("Headset On.");
    6.             //HeadsetOn();
    7.         }
    8.         else if (isHeadsetOn && !SteamVR_Input._default.inActions.Proximity_Sensor.GetState(m_inputSourceDevice))
    9.         {
    10.             Debug.Log("Headset Off (cancellable)");
    11.             //StartCoroutine(HeadsetOff());
    12.         }
     
  2. dmennenoh

    dmennenoh

    Joined:
    Jul 1, 2015
    Posts:
    379
    I can see the proximity sensor working in the Input Debugger, but I can't figure out how to add it to default actions like that code snippet suggests.
    I tried adding it myself and then I get an all black page when trying to bind it or use the debugger.
    Anyone know of a tutorial on this?
     
  3. beyondtheline

    beyondtheline

    Joined:
    Feb 1, 2017
    Posts:
    2
    looking for the same thing. did you solved that?
    Is there a way to define input bindings for HMD?
     
  4. dmennenoh

    dmennenoh

    Joined:
    Jul 1, 2015
    Posts:
    379
  5. EyePD

    EyePD

    Joined:
    Feb 26, 2016
    Posts:
    63
    I had to manually edit the .json as described in the issue because as of SteamVR 2.2 the proximity sensor is still not exposed in the bindings UI. I spent a lot of time trying to get it to work because I didn't realize that the "SteamVR Input Live View" built into Unity doesn't actually show any activity until you try to access that value in code. This is especially confusing because the "Input Debugger" you can launch from the web based bindings UI does show proximity activity. It wasn't until I added the following code that I saw any activity for "HeadsetOnHead" within the Unity based Live View:

    Code (CSharp):
    1. SteamVR_Action_Boolean headsetOnHead = SteamVR_Input.GetBooleanAction("HeadsetOnHead");
    2. bool onhead = headsetOnHead.GetStateDown(SteamVR_Input_Sources.Head);
     
    hwankim90 likes this.
  6. bart42

    bart42

    Joined:
    Dec 29, 2014
    Posts:
    5
    whats the status on this?