How can you detect a VR environment from GDScript (so a redirect scene can pick the correct starting scene)

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By thoth

I have a project that supports both VR (Oculus Quest 1) and desktop.

I currently set the android scene as the main scene, and run the desktop using the Play Scene F6 button with the desktop scene active.

I have read that it is possible to use a redirect scene whose main job is to get_tree().change_scene(url) . The question then becomes: how do I detect that the app is running on a VR headset in GDscript so I can switch to the environment-appropriate scene?

:bust_in_silhouette: Reply From: alexMunro

I have the same problem with my port of BeepSaber to Godot4. The game tries to load a VR plugin if none is found, the VR Simulator is used as a fallback. But I do not have an Oculus Quest, instead I use a Valve Index with Monado and Libsurvive. So I also want to detect the type of VR runtime and HMD. So you might wan’t to have a look at

:bust_in_silhouette: Reply From: thoth

Based on the code link from alexMunro I have the following kludge:

extends Spatial

func _ready():
	var interface = ARVRServer.find_interface("OVRMobile")
	if interface:

That is a script which is attached to the root (and only node) of my main scene.

I am including my code here in case his link ever gets 404-d. His code covered several other options for the argument to ARVRServer.find_interface() .