Oculus not starting in Build mode but works fine in Edit/Play mode

So i’ve had this problem in both unity 5.3.2 and 5.3.4 now, it was working a while back but when I tested it today it no longer works and I have no idea why.

I have my oculus turned un and the config util runninng in the background. I try the oculus demo scene… works. Try my game in the editor, works just fine. Compile and build my game, turn it on, does not start in oculus mode. Ever!

Checked out the logs and there are no errors. It even says

[VRDevice] Successfully created device
stereo.

I’ve even tried implementing my own code to turn it on

 if(VRDevice.isPresent==true)
        {
            Debug.Log("A VR DEVICE HAS BEEN DETECTED FFS!");
            VRSettings.enabled = true;
            VRSettings.showDeviceView = true;
        }   

It prints out that message in the log, no errors thrown, but the game still doesn’t start in oculus mode.

Any ideas, suggestions?

Thanks for your time.

EDIT: To provide a little update on this. I’ve made the following code:

if (VRDevice.isPresent == true)
                {
                    Debug.Log("BEFORE SETTING: "+VRDevice.family + " - " + VRDevice.model);
                    VRSettings.loadedDevice = VRDeviceType.Oculus;
                    Debug.Log("AFTER SETTING: "+VRDevice.family + " - " + VRDevice.model);
                    Debug.Log("A VR DEVICE HAS BEEN DETECTED FFS!");
                    VRSettings.enabled = true;
                    Debug.Log("VRSETTINGS shows as: " + VRSettings.enabled);
                    VRSettings.showDeviceView = true;
                    Debug.Log("VRSETTINGS showdeviceview: " + VRSettings.enabled);
                }

This is what i get in the editor:

A VR DEVICE HAS BEEN DETECTED FFS!
UnityEngine.Debug:Log(Object)
splashScreenAnimation:Start() (at
Assets/scripts/splashscreen/splashScreenAnimation.cs:52)

BEFORE SETTING: oculus - Oculus Rift
DK2 UnityEngine.Debug:Log(Object)
splashScreenAnimation:Update() (at
Assets/scripts/splashscreen/splashScreenAnimation.cs:80)

AFTER SETTING: oculus - Oculus Rift
DK2 UnityEngine.Debug:Log(Object)
splashScreenAnimation:Update() (at
Assets/scripts/splashscreen/splashScreenAnimation.cs:82)

A VR DEVICE HAS BEEN DETECTED FFS!
UnityEngine.Debug:Log(Object)
splashScreenAnimation:Update() (at
Assets/scripts/splashscreen/splashScreenAnimation.cs:83)

VRSETTINGS shows as: True
UnityEngine.Debug:Log(Object)
splashScreenAnimation:Update() (at
Assets/scripts/splashscreen/splashScreenAnimation.cs:85)

VRSETTINGS showdeviceview: True
UnityEngine.Debug:Log(Object)
splashScreenAnimation:Update() (at
Assets/scripts/splashscreen/splashScreenAnimation.cs:87)

That’s awesome, that’s what I expect! Nothing wrong :slight_smile: Now for the compiled game:

[VRDevice] Successfully created device
stereo. A VR DEVICE HAS BEEN DETECTED
FFS! (Filename:
C:/buildslave/unity/build/artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp
Line: 37)

Setting up 1 worker threads for
Enlighten. Thread → id: 3758 →
priority: 1 BEFORE SETTING: stereo -
(Filename:
C:/buildslave/unity/build/artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp
Line: 37)

AFTER SETTING: stereo - (Filename:
C:/buildslave/unity/build/artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp
Line: 37)

A VR DEVICE HAS BEEN DETECTED FFS!
(Filename:
C:/buildslave/unity/build/artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp
Line: 37)

VRSETTINGS shows as: False
(Filename:
C:/buildslave/unity/build/artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp
Line: 37)

VRSETTINGS showdeviceview: False
(Filename:
C:/buildslave/unity/build/artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp
Line: 37)

Soooo something’s wrong with the compiled game not detecting my oculus properly. But I’m not sure really what to do from here :confused:

EDIT 2: Okay bodged together a solution!

It seems that for some reason, my built code of unity is unable to detect what VR headset I have connected, but it can detect one is connected, returning a result of empty string for the headset model. Thus i’ve implemented the following code:

 if(VRDevice.isPresent==true && string.IsNullOrEmpty(VRDevice.model))
        {
            Debug.Log("EMPTY VR DEVICE DETECTED!");
            VRSettings.loadedDevice = VRDeviceType.Oculus;
            VRSettings.enabled = true;
            VRSettings.showDeviceView = true;            
        }   

Which works fine for now. I’m pretty sure the problem is isolated to just my PC since it was working before without a problem so this shouldn’t affect too many people.

In the future I will want to add steam VR support so what i’m going to do is change the code above to just display a message of “VR Headset not Recognized” and then have a command line parameter to force on different types of VR headsets.

So for now, I guess I answered my own question… But if anyone figures out why this is happening, please let me and everyone else know.

For me this took rebuilding it with the Windows_64 bit architecture. Then it worked like a champ.

So a bit of progress and a behavior update. After playing with it a bit, turning on and off etc, now the results are a bit different. Something seems to be locking up my oculus and not letting go once i exit the application.

Here’s the new behavior:

I run the built game, all of a suddeon it magically works, but still reports that it doesn’t detect the device type. Then it hits the line VRSettings.loadedDevice = VRDeviceType.Oculus and it magically starts working, which is awesome.

However if i close the application, then run it again, it freezes when it’s supposed to switch to oculus. Alt+F4, launch again and it works again.

There may be something wrong on my pc and I’m afraid i don’t have another PC to test on, which is slightly frustrating.

EDIT : Okay bodged together a solution!

It seems that for some reason, my built code of unity is unable to detect what VR headset I have connected, but it can detect one is connected, returning a result of empty string for the headset model. Thus i’ve implemented the following code:

  if(VRDevice.isPresent==true && string.IsNullOrEmpty(VRDevice.model))
         {
             Debug.Log("EMPTY VR DEVICE DETECTED!");
             VRSettings.loadedDevice = VRDeviceType.Oculus;
             VRSettings.enabled = true;
             VRSettings.showDeviceView = true;            
         }   

Which works fine for now. I’m pretty sure the problem is isolated to just my PC since it was working before without a problem so this shouldn’t affect too many people.

In the future I will want to add steam VR support so what i’m going to do is change the code above to just display a message of “VR Headset not Recognized” and then have a command line parameter to force on different types of VR headsets.

So for now, I guess I answered my own question… But if anyone figures out why this is happening, please let me and everyone else know.

hey man the same thing was happenening to me, so I research all day to fix this problem, and I found that my folder and the .exe have some special characters, so what i did was to to generate a new build in a new folder wihouth the special characters, and that fix the problem. hope this helps.