This works pretty well in “Play Mode”, but not in the builded EXE File. Isn’t it possible to set this up for a build ? My aim is to toggle between “None” and “Split” as loaded device. Does anyone has an idea ?
It would appear the token is currently “split” not “Split”. (I know it’s capitalized in the documentation sample you used.) I added VR support for Mock HMD (split) and None to a player and was able to switch between them with the following script.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.XR;
public class ModeToggle : MonoBehaviour
{
public string[] devices;
public int devIdx;
// Use this for initialization
void Start()
{
devices = XRSettings.supportedDevices;
LoadDevice(0);
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
LoadDevice(devIdx + 1);
}
private void LoadDevice( int idx )
{
devIdx = idx % devices.Length;
StartCoroutine(LoadDevice(devices[devIdx]));
}
private IEnumerator LoadDevice(string newDevice)
{
if (string.Compare(XRSettings.loadedDeviceName, newDevice, true) != 0)
{
Debug.Log("Loading: " + newDevice );
XRSettings.LoadDeviceByName(newDevice);
yield return null;
XRSettings.enabled = true;
}
}
}
Thanks Mike for your answer. Finally, I got my script working after seeing your solution. The problem was that I did not add “Split Stereo (non head-mounted device)” to the supported devices. This setting is not available through “Player Settings” in Unity 2017.4, so i had to add it programatically through an editor script.
PlayerSettings.virtualRealitySupported = true;
UnityEditorInternal.VR.VREditor.SetVREnabledDevicesOnTargetGroup(BuildTargetGroup.Standalone, new string[] { "none", "split" });