Search Unity

Resolved Knowing which VR Headset (HMD) is currently use

Discussion in 'XR Interaction Toolkit and Input' started by Akravator, Feb 1, 2021.

  1. Akravator

    Akravator

    Joined:
    Aug 8, 2017
    Posts:
    19
    Hi2.,
    How do i know via script which headset is currently being used by the player at the beginning of the app ?
    for example if the player use HTC Vive, Oculus Rift, Oculus Quest or even HP Reverb ?

    I use XR Plugin management with Oculus and OpenVR Loader
    I also have SteamVR installed in my Asset. But no Oculus Integration package
     
  2. joejo

    joejo

    Unity Technologies

    Joined:
    May 26, 2016
    Posts:
    958
    There really isn't a way to do that. The purpose behind XR SDK is to abstract the differences out so you don't have to worry about the hardware in general.

    That said that are a couple ways you may be able to figure this out:

    1) Get the active loader from XR Plug-in Management and try casting it to a loader type for one of the target platforms. You'll need to know the loader type AND have that type compiled into your program for this to work.
    2) You can look at the information for the hardware provided by the XR Input system. The propertied in InputDevice are probably the best way to get that. Make note that the information presented here is information we get directly from the system/hardware and you may need to translate it to something that you can use.
     
  3. Akravator

    Akravator

    Joined:
    Aug 8, 2017
    Posts:
    19
    I understand then.

    and maybe a bit of beginner question:
    How do i get the object name that i currently grab with XR Controller ?
    i read the documentation but perhaps i miss something
     
  4. chris-massie

    chris-massie

    Unity Technologies

    Joined:
    Jun 23, 2020
    Posts:
    231
    The XR Controller component just provides the input to an Interactor component. You probably have an XR Ray Interactor or XR Direct Interactor on the same GameObject as the XR Controller, and it's those Interactor components that actually do the grabbing of an XR Grab Interactable. They do so by "selecting" an Interactable.

    So if you want to get the name of the object you are grabbing, you would need a reference to the Interactor and use the selectTarget property, and then name.
     
  5. Akravator

    Akravator

    Joined:
    Aug 8, 2017
    Posts:
    19
    Thankss Chris! it workkss perfectly!!!
     
  6. Akravator

    Akravator

    Joined:
    Aug 8, 2017
    Posts:
    19
    Hi Christ., Sorry for re-opening this forum.
    However, how do i temporarily disable the XRGrabInteractable? So that no one can grab that object?

    I have tried disabling the Collider, clearing the Colliders in the XRGrabInteractable and freezing the position on the Rigidbody.
    but none seems to works 100%.

    The collider disabling kinda works., but if i have my hand (just hovering, without grabbing) and then i disable the collider
    I still able to grab the object. However, if i move my hand outside the gameObject, then it will work.
     
  7. chris-massie

    chris-massie

    Unity Technologies

    Joined:
    Jun 23, 2020
    Posts:
    231
    You can disable the XRGrabInteractable by setting enabled false. That will unregister it from the XRInteractionManager so it won't be able to be hovered or selected, and even cancel out any existing hover or selection. Setting enabled back to true will re-register it again. You could also clear out its interactionLayerMask, and then restore the value when you want to re-enable it.

    To explain why disabling the Collider doesn't work in that case, Direct Interactor utilizes OnTriggerExit to detect when a Collider leaves it, but that method doesn't get called when the Collider is disabled instead.
     
  8. Akravator

    Akravator

    Joined:
    Aug 8, 2017
    Posts:
    19
    And as alwayss hatss off to you Chris!!
    Thanks for your amazing solution and explanation!
    I appreciate it... ^^,
     
    chris-massie likes this.
  9. webster

    webster

    Joined:
    Jun 8, 2013
    Posts:
    21
    I get that abstraction is generally a good thing. The problem, a big problem for me, is I want to display the matching hardware in-scene. If they are on Quest 1, I want dark Touch controller models. Quest 2 has white ones, etc. And if mulitplayer, I'd like the remote avatars to be holding their respective controllers, wearing their particular headsets. I'm very surprised there isn't just one 'device ID' field that says 'VivePro' or 'OculusQuest1' or something like that. Are you sure there is no way to do this? I would hate to go back to the old system(s)

    OR is this what I'm really looking for?: https://docs.unity3d.com/ScriptReference/SystemInfo.html
     
    Last edited: Mar 11, 2021
    VirtualDawn and YerBoh like this.
  10. webster

    webster

    Joined:
    Jun 8, 2013
    Posts:
    21
    See this: https://docs.unity3d.com/ScriptReference/SystemInfo.html

    Particularly https://docs.unity3d.com/ScriptReference/SystemInfo-deviceModel.html
     
  11. lloydsummers

    lloydsummers

    Joined:
    May 17, 2013
    Posts:
    359
    Except that this stops developers from showing the right controllers for their headset - which is kind of important for tutorials and to show people where things like buttons are (when, you know, their view is obstructed by a headset). Unless of course OpenXR and Unity isn't meant to be used for training / teaching / education / industrial use etc. In which case using abstract buttons that don't match the real world is perfectly fine.