Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

How to determine if app is running on HoloLens

Discussion in 'VR' started by JohannesPTC, Jun 7, 2016.

  1. JohannesPTC

    JohannesPTC

    Joined:
    Oct 9, 2012
    Posts:
    13
    We would like to know in our code if an app is running on a HoloLens device or any other platform, like a surface tablet. Is there a #define or runtime check we could use for that?

    We thought about using VR.WSA.WorldManager.state and checking if it is Activating or Active. Is that the best and most reliable way to do that?
     
  2. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,504
  3. JohannesPTC

    JohannesPTC

    Joined:
    Oct 9, 2012
    Posts:
    13
    Thanks Tautvydas, we'll use that.
    Since our code is also running on platforms that support other VR SDKs (e.g. Oculus), We need to check for the device name as well. I noticed that the device type enum has been deprecated in 5.4, so I'm using VRSettings.loadedDeviceName.Equals("HoloLens"). That seems to work for now.
    My only question is whether this will work on future Windows holographic devices from other OEMs?
     
  4. thep3000

    thep3000

    Unity Technologies

    Joined:
    Aug 9, 2013
    Posts:
    399
    If future windows holographic devices use the same apis as HoloLens does today, then yes :)
     
  5. Rodolfo-Rubens

    Rodolfo-Rubens

    Joined:
    Nov 17, 2012
    Posts:
    1,196
    Hi, sorry to necro this thread.

    I'm trying to find if the app is running on HoloLens or in the desktop but seems like using the loadedDeviceName always return WindowsMR on desktop (using the Odyssey) and on the HoloLens... Any way to know which setup we are like MR, AR, VR?
    --
    edit:
    Also tried the SystemInfo.deviceType but it seems like the HoloLens is considered a Desktop so I still can't differentiate between the PC and the HoloLens using this variable.
     
    Last edited: Feb 25, 2019
  6. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,504
    On "Windows.Graphics.Holographic.HolographicDisplay" class there's a property called "IsOpaque". If it returns true, you're running on a VR device. If it returns false, you're running on AR.
     
    Rodolfo-Rubens likes this.
  7. Rodolfo-Rubens

    Rodolfo-Rubens

    Joined:
    Nov 17, 2012
    Posts:
    1,196
    Ah, that's perfect, I will take a look!

    Thanks @Tautvydas-Zilys.
     
  8. Regretful123

    Regretful123

    Joined:
    Nov 5, 2014
    Posts:
    18
    This link is broken. I need to find a way to distinguish between Hololens 1 and Hololens 2. For performance reason, I need to be able to identify between these two devices. Using Windows.Graphics.Holographic.HolographicDisplay will not help because it would return true for both Hololens 1 and Hololens 2.
     
  9. joejo

    joejo

    Unity Technologies

    Joined:
    May 26, 2016
    Posts:
    958
    You have to use Windows APIs for Contract Checking to do this. You have to check for
    "Windows.Foundation.UniversalApiContract" version 8. If that is true and you are running in VR then you are on HL2. If that is false and you're running in VR then you are on HL1.
     
    Regretful123 likes this.