Search Unity

Resolved How to check in script for XR Settings if HMD is present or plugin is actively enabled to load

Discussion in 'XR Interaction Toolkit and Input' started by metaphysician, Jan 3, 2021.

  1. metaphysician

    metaphysician

    Joined:
    May 29, 2012
    Posts:
    190
    hey folks i've got a situation in a course i'm teaching where myself or my students may be using the Editor both in Standalone Mode and also in VR. the new XR Toolkit and Input system manage the switch off very well which is more convenient than the VRTK method of completely different rig setups. so visually the Editor mode without VR and with VR are pretty close to each other in terms of look and feel in the Game View but there's still some issues i'd like to tweak visually if the VR HMD and controllers are present or if not it falls back to standard Desktop layout and disables the controller objects.

    anyway, how do you check if the HMD and controllers are present or not via a simple flag at startup in a script? alternately is there a way to check the XR plugin settings from a script to see if any are active? i'm in Unity 2020.1 BTW. thanks in advance!
     
    jmcgraw961 likes this.
  2. Fexelein

    Fexelein

    Joined:
    Dec 27, 2020
    Posts:
    6
  3. joejo

    joejo

    Unity Technologies

    Joined:
    May 26, 2016
    Posts:
    958
    You can't really check if the HMD is present without starting VR, but you can use the MockHMD to switch between XR and Non-XR more easily than using an actual headset.

    About the Mock HMD XR Plugin | MockHMD XR Plugin | 1.1.3-preview.1 (unity3d.com)

    If you just want to check if XR is active you can check the XRGeneralSettings.Instance?.Manager?.activeLoader to see if it is non-NULL. If it's not null, then XR is actively running.

    About the XR Plug-in Management package | XR Plugin Management | 3.2.17 (unity3d.com)
     
    jmcgraw961 likes this.
  4. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,411
    That returns not-null, even with headset is not connected.

    Still searching for a way to detect whether to start VR or PC mode.. (if no headset is connected)
    In steamvr its pretty much automatic, you get one error that hmd not found, and you are in PC mode.