How to detect whether a user is using a VR device?

I know how to do it with another library

Does Babylon have its alternative for this?

Hey @gunpowderfans , how are you doing?

Maybe @RaananW has some information on this.

I know you can use VRExperienceHelper.isInVRMode to check if the user is currently in a VR experience, but I’m not sure if we provide a way for you to know the specific device.
VRExperienceHelper | Babylon.js Documentation (babylonjs.com)

I wish the platform detect libraries and packages would catch up. If you are concerned mostly with Quest2 like my case, it will show up as linux/mobile in this platform-detect - npm is one way to catch that device

There is a pre-Engine check built into the framework to check:
BABYLON.IsSessionSupportedAsync()

If you have any interest in AR as well as VR, you’ll have to call it twice. Devices that can do both are now the bar to hit. You need to nest 2 calls to find out both.

I actually took the code for that function into my codebase, so I can detect this even prior to BABYLON script being loaded.

@br-matt, think this is more elegant. While npm might actually work in Babylon Native, writing an add-in is daunting.

1 Like

That is a nice way for sure, will try that out

It is in session manager, Babylon.js/webXRSessionManager.ts at master · BabylonJS/Babylon.js · GitHub

The full call would be BABYLON.WebXRSessionManager.IsSessionSupportedAsync('immersive-vr'). In my last post, I copied from my code. There is no direct BABYLON level call, but this is both static & can be called prior to instancing Engine.

2 Likes

Just wanted to add - is session supported does not necessarily means that there is a headset connected, but that the browser supports the API. kind of like “if i want a vr session on this device and there is a headset connected, will I be able to enter the session?”. AFAIK there is no way to check if there is an actual device connected (probably to prevent fingerprinting), but I will be happy to learn something new :slight_smile:

1 Like

Not totally sure what fingerprinting is, but it might also be to allow a form factor where the processing takes place on a different device than the display. I remember Apple pundents / fanboys a few years ago, saying the processing might be on the phone to reduce price. The flaw in that is Apple is not a budget producer.