How can I Launch Build in nonVR or VR mode? Detect at run time?

I’m attempting to make a project that, when built, can be opened in VR mode or non-VR mode. I would like players to be able to launch the game in non-VR mode and at run time, detect that it is not running in VR mode and spawn a non-VR character prefab. However, if the build started in VR mode then a different VR character prefab should be spawned.

Does anyone have any suggestions on how to do this? Should it be a launch option like the prelauncher dialog gives the option of non/VR mode?

Right now, if I open the build on my PC with my Vive attached the game starts up SteamVR before launching into the game in VR mode. However if I open the game on a PC without a VR headset attached the game opens into what seems to be a standard FPS scene. I’m hoping to have more control over whether or not I launch into VR mode.

On top of that I’d like to know in game which mode was chosen so I can spawn the appropriate character prefab.

Any suggestions are welcome, thank you!

As testing in VR is more timeconsuming that on a “normal” screen, i also needed a way to quickly switch between VR and non-VR more without going through the build settings each time.

I have a GameManager class with a public bool where i can switch VR mode on or off. This also switches between two different cameras. Maybe you can use this as a basis.

In the player settings VR support must be enabled.

(The class is not complete, i just posted the relevant parts)

using UnityEngine.VR;

public class GameManager : MonoBehaviour
{
  public bool _use_vr = true;
  public Camera default_camera;
  public Camera vr_camera;

  void Awake()
  {
    Debug.Log("GameManager use_vr = " + _use_vr );
    VRSettings.enabled = _use_vr;
    default_camera.gameObject.SetActive( !UseVR() );
    vr_camera.gameObject.SetActive( UseVR() );
  }

  public bool UseVR()
  {
    return _use_vr && VRDevice.isPresent;
  }
1 Like

This sounds like a great place to start, thank you very much!

1 Like