i’m experimenting with making a game support both flat screen and VR, and i would like to be able to switch between the two while the game is running.
enabling OpenXR in the project settings means the game always runs in OpenXR mode, so if the rest of the game is still set to ‘flat screen mode’ (no xr viewport, no xr nodes, maybe no OpenXR runtime available at all) it’ll unnecessarily start the system’s OpenXR runtime and/or cause various fun errors.
the documentation and my own testing suggest there’s no way to initialize OpenXR without enabling it in the project settings (causing the aforementioned issues), so i doubt it but in case i’m missing something: is there any way at all to do what i want? or will restarting the game always be necessary to switch between modes?
This has been a bit of a troublesome issue due to the design of OpenXR. When using the Vulkan back end (mobile or forward+ renderer), OpenXR takes ownership of Vulkan and has to be setup first before Vulkan can be setup. That creates an either/or situation where your game either starts in VR or in pancake mode.
There are ways around this but they have other drawbacks and added complexity so they currently aren’t implemented in Godot.
Now this only applies to Vulkan, when running in OpenGL (compatibility mode) you can leave OpenXR turned off in the project settings, and instead call initialize on the OpenXR interface when you want to switch to OpenXR, and call uninitialize when you want to return to pancake mode (same as it worked in Godot 3.x). There have been reports however that there can be issues with this that I have yet to investigate further.
What others have done as an approach so far is to use the --xr-mode on/off command line switch to start Godot either with OpenXR enabled or disabled. Starting Godot initially with xr disabled, and if the user wants to switch to XR, it starts a new instance of Godot with --xr-mode on and close (or pausing) the pancake version.
thanks for the detailed reply! i’d much rather stick with the Vulkan renderers for desktop projects, so i guess restarting is unavoidable. i hadn’t thought of the last approach though, so with that i’ll at least be able to make restarting as seamless as possible