Skip to main content
Participant
May 8, 2016
Solved

Cursor Lock unavailable ?

  • May 8, 2016
  • 31 replies
  • 6821 views
Hello,
I recently tried to update some old "0.6" app to the new "1.3" drivers - it's a seated experience where the user can look at various UI elements to 'click' them.

For this, I lock the cursor in the middle via Cursor.lockState and just use the standard Unity UI (with in-world Canvas). Everything worked fine before, and still work in the editor - but not once built.

With a built app, if I have both the Oculus API and "Virtual Reality Support" enabled (in Unity's player options), the LockState stay at "none" - whatever my scripts try to do. Removing the Oculus plugin or unchecking "VR Supported" put thing back to normal, but then the Oculus doesn't work.

This is very problematic because it make the whole "look at a button to press it" concept very uncomfortable, as it force the user to manually center his cursor at the app's start (and moving accidentally your mouse mess up everything). This problem appear even on a new, nearly empty project with just the Oculus plugin and a few scripts trying to mess with the cursor's state.

Is this an intended behavior, or a bug ?
In any case, does someone have a way to correct it ?

I could add Colliders to every UI elements and then perform ray test from the camera, but that's basically recreating Unity's UI/EventSystem in a less optimized way.
This topic has been closed for replies.
Best answer by vrdaveb
Using the Windows mouse cursor with VR is not recommended. We've written a better gaze-based cursor system for Unity's UI, which you can read more about at https://developer.oculus.com/blog/unitys-ui-system-in-vr.

31 replies

Inspiring
May 27, 2016
Thanks for posting the bug report. Can you let me know the case number when Unity emails it to you? After talking to Unity, it sounds like this behavior is not intended. Neither Unity nor I can reproduce it. If you download the Oculus Utilities and open the scene Assets/OVR/Scenes/Room.unity, it sets Cursor.lockState = CursorLockMode.Locked and it works as expected with the Rift.
Up and Coming
May 27, 2016
Here is the case number (Case 800978)

Maybe it relates to Unity version I'm using. I'm on the latest 5.4 beta at the moment. I don't know if you can get access to the zip file I sent. If not I can email it you.
Inspiring
May 27, 2016
Thanks, I was using 5.3. Now I can reproduce it. Working with Unity to solve it.
Up and Coming
May 28, 2016
That's really good to here. Not being able to reproduce problems that people have with Whirligig is the bane of my life :)
Participant
May 28, 2016
Just to chime in: I believe I experienced the same bug when I updated my port of Quake to the 1.4 SDK. It's using SDL's `SDL_SetRelativeMouseMode(SDL_TRUE);` to lock the cursor. However, it seems that OVR "steals" focus from the game or otherwise removes the mouse lock again.

My workaround was to continually call `SDL_SetRelativeMouseMode(SDL_TRUE);` each frame for the first 900 frames the game is running: https://github.com/phoboslab/Quakespasm-Rift/blob/master/Quake/vr.c#L580-L586

Inspiring
May 30, 2016
This sounds like a separate issue because it doesn't occur with most VR apps (such as ones built in Unity 5.3). I'm not aware of any code in the runtime that would steal focus or prevent cursor locking, but we'll take a look.
Up and Coming
June 9, 2016
Just to let you know my progress. I've reported the bug to Unity and they have managed to recreate it so hopefully there will be a fix soon. I can say that currently though as of Unity UNITY 5.4.0B21 it is still there.

Fingers crossed they sort it in the next build :)
Up and Coming
June 20, 2016
A continuation in my progress. UNITY 5.4.0B22 does not yet have a fix for this.

I really hope they fix this soon :(
Inspiring
June 20, 2016
Looks like Unity is still working on this. They have reproduced it, but there isn't a fix yet. Keep an eye on case 800978 for updates.
Up and Coming
June 20, 2016
Thanks, thats good to know. Oddly I've found in this Unity build that the mouse does lock eventually but I can't work out what happens to make it do so. It takes about 30 seconds but there is nothing obvious happening that I can figure yet. If I come up with an explanation I let you know :)