Search Unity

How To Detect Which VR Headset is Active in Script (Oculus or Vive)

Discussion in 'AR/VR (XR) Discussion' started by Don_NVS, Nov 23, 2018.

  1. Don_NVS

    Don_NVS

    Joined:
    Dec 23, 2013
    Posts:
    34
    Hello Everyone. I am working on a VR game that has a Non-VR mode so if the player wants to continue but doesn't want to do so in VR he/she can. I am writing a custom Input Manager to detect inputs from the following controllers: Xbox One, PS4, Oculus Touch, Vive, and Knuckle Controllers.

    To ensure my Input Manager is working properly I need to know the following:
    - Which Controller is Being Used
    - Which Headset if any is Active

    I wrote an Input Manager for each of the controllers so they can be mapped differently if need be down the road. Each Input Manager is on a Game Object and I want to turn them on and off depending upon which controller is being used at the time.

    Example:
    - If the player turns VR on and is using a Vive with Knuckle Controllers, I want to turn off (deactivate) the Input Managers for the Xbox One Controller, PS4 Controller, Vive Controllers, and Oculus Touch Controllers.
    - I just want the Knuckle Controller Input Manager to be active in this scenario.

    The Goal:
    The goal is to write an Input Manager system that broadcasts when an input happens to all the other scripts. That way a game can be built and the scripts don't care if the inputs came from an Xbox Controller, Keyboard, PS4 Controller, Oculus Touch, Vive or Knuckle Controllers. My hope is it will be easier to add support for new controllers as they come out without rewriting the game.

    I know how to detect if VR is enabled or disabled which makes the Xbox One and PS4 controllers easy to do, but I'm not sure how to detect the difference between whether that VR headset is an Oculus or Vive and if the user is using the Touch Controllers, HTC Vive Controllers, or Knuckle Controllers. I've tried Googling the answer and only found device.connectedheadset but that doesn't seem to work, especially when detecting the Vive Controllers and Knuckle Controllers.

    Any suggestions would be greatly appreciated. Also, Valve sent me a set of Beta Knuckle Controllers so I can fully test this out with all controllers.

    Also, I have a PS4 Dev Kit and plan on porting to PSVR at a later time which is why I built the Input Manager for the PS4 controller. That should be much easier to detect based on whether the game is playing on a PS4 or not and if it is in VR mode or not.
     
    Last edited: Nov 23, 2018
  2. unity_KRlGyY8LMl9-Og

    unity_KRlGyY8LMl9-Og

    Joined:
    Sep 2, 2020
    Posts:
    3