02 April 2018

How to detect your Windows Mixed Reality app is actually running on a head set

Very short and small tip – Windows Mixed Reality can run on a HoloLens, on an immersive headset – but although the Store warns about necessary hardware to run the app, there’s basically nothing stopping users from installing the app on a regular Windows PC. We can discuss whether or not that is a smart thing to do, but I approach it from the other side – if a users runs my app on a device that has no immersive capabilities, I can either quit the app, or offer her or him some basic functionality, show menus that can be easily controlled by a mouse click, whatever.

It is actually hilariously simple to detect that: just check

UnityEngine.XR.XRDevice.isPresent

Which returns true if your app is running on either an immersive headset or a HoloLens, and false if the user has started it on some other Windows device.

Thanks to Peter Nolen for the tip!

No comments: