No change of VR Mode possible? (solved)

It feels like a joke. Is there any Unity Version available where I can change the VR Mode? Where is the sense with LoadDevice or XRSettings.enabled when its not useable?

I know I asked this question months before… there was the recommendation using Unity 5.5 and GoogleVR 1.1

We are now at 2017.3 beta (my last wasteful test) and Google VR 1.100… and still no progress. Can you explain this to me? I want to make use of new features… want to build cross plattform VR Applications… But its not possible? I dont unterstand whats going on. Is cardboard not supported anymore? Would be nice to know… because my Clients still demand it… I need to build cardboard for android, ios and gearVR… I need everytime the possibility to change between nonvr and vr…I dont want to switch between framework and unityversion in the same project…

I would like to have an explanation… do I have to stick at old unity versions and google vr sdk? This kind of chaos is also responsible for bad VR Applications!

What, exactly is the issue you are running into or what are you trying to do? It should be possible to support Google VR on both Android and iOS with the same application right now.

Gear VR is a different issue. In order to support Gear VR, there is a manifest entry added to the application to mark it as a Gear VR application. The OS catches that entry BEFORE Unity even gets a chance to do anything and forces the app into the Gear VR transition screen. The only way to support Gear VR AND Google VR right now is to create 2 applications, one for each device/store. Samsung and Oculus are working on this issue as it will also fix the issue where Gear VR applications are unable to go into and out of VR mode (again, an OS issue, not Unity).

1 Like

Hi Joejo,

the problem isn’t GearVR. I just want to use a modern Unity-Version. The problem is Cardboard. I want to switch between VR Mode and Non-VR-Mode at Runtime. But it seems impossible with actual Unity or GoogleVR Versions. So I am forced to use an old Version of both. But I want to use modern features and the same Input-Base for GearVR. So at the moment I need to use two complete different projects and Unityversions.

I dont understand why Daydream is so much supported, there are just some few devices and cardboard is a total mess but reaches almost any device on the market.

There should be no problems with switching in/out of VR in Cardboard. We test this all the time here. Can you make a real simple repro project that demos the problem and post a link to it?

Hi Joejo,

as I build the really small testproject I got an Idea, that I really needed to test and tataa… I solved it!

At first I have a 2D NonVR Mainmenu… then I choose VR or NonVR Mode. When the scene is loading it recognizes which option I choose and loads the VR Mode via IENumerator… and than nothing… until I put an WaitForSecond(0.5f) Timer!!!
Now it’s working as intended. Sometimes the orientation is a little wrong. Unity should strongly create some smallscale Tutorials or UserGuides in the documentation where such fallpits will be explained… I was loosing over two weeks because of this problem! So I was pretty desperate…

https://1drv.ms/u/s!AnxX1Cbp1-AljloVNciE8xVohQI7

Here is my simple project.

Thank you for your ear! :slight_smile:

1 Like

Yes, you have to give the VR system at least one frame to handle enable and/or LoadDeviceByName.

Correct technique to tell if you’ve waited long enough would be to follow this part of the docs:
In order to check for success, check XRSettings.loadedDeviceName on the next frame.

1 Like

I thought it is enough to have a yield return null after LoadDeviceByName. But it only works if I have another yield return null before XRSettings.enabled. Because I call them seperatly.

So maybe its helpful to put this hint to this page Unity - Scripting API: XR.XRSettings.enabled

IEnumerator LoadStartVR(bool enabled)
{
yield return null;
XRSettings.enabled = enabled;
}

    private void Start()
    {
        StartCoroutine(LoadDevice());
        if (VRSceneConfig.vrEnabled)
        {
            SetStartVR(true);
            Debug.Log("VR ein: " + VRSceneConfig.vrEnabled);
        }
        else
        {
            SetStartVR(false);
            Debug.Log("VR aus: " + VRSceneConfig.vrEnabled);
        }
    }

    private void Update()
    {
        if (!XRSettings.enabled)
        {
            if (Application.isEditor)
            {
                transform.Rotate(0f, Input.GetAxis("Mouse X"), 0f, Space.World);
                transform.Rotate(-Input.GetAxis("Mouse Y"), 0f, 0f, Space.Self);
            }
            else
            {
                transform.localPosition = InputTracking.GetLocalPosition(XRNode.CenterEye);
                transform.localRotation = InputTracking.GetLocalRotation(XRNode.CenterEye);
            }

            if (Input.GetKey(KeyCode.Escape))
            {
                UnityEngine.SceneManagement.SceneManager.LoadScene(0);
            }
        }
        if (XRSettings.enabled)
        {
            if (Input.GetKey(KeyCode.Escape))
            {
                ToggleVR();
            }
        }

    }

    public void ToggleVR()
    {
        SetVR(!XRSettings.enabled);
    }

    public void SetVR(bool enabled)
    {
        StartCoroutine(LoadVR(enabled));
    }
    public void SetStartVR(bool enabled)
    {
        StartCoroutine(LoadStartVR(enabled));
    }
    IEnumerator LoadVR(bool enabled)
    {
        yield return null;
        XRSettings.enabled = enabled;
    }

    IEnumerator LoadStartVR(bool enabled)
    {
        yield return null;
        XRSettings.enabled = enabled;
    }

    IEnumerator LoadDevice()
    {
        XRSettings.LoadDeviceByName("cardboard");
        yield return null;
    }
}
1 Like

Official doc

5 Likes