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

Up and Coming
June 20, 2016
Here is the page if anyone want to Vote it up to get fixed.
https://issuetracker.unity3d.com/issues/cursor-dot-lockstate-equals-cursorlockmode-dot-locked-doesnt-work-with-native-oculus-vr-support

Update:
Unity 5.4.0b22
I've discovered a thing regarding this. Once you start your application the mouse isn't locked but you can get it locked by clicking off the player and then clicking back on the player. Then it seems the mouse is locked again. It means it's at least working a little. I don't know if this is a new thing but it seems to be better than it was before.


Up and Coming
August 11, 2016
I can confirm that this is still an issue in the build 5.4.0F1. If you're interested in getting this fixed visit the bug page and up vote the ticket.
Inspiring
August 11, 2016
Thanks for re-testing. Unity has reproduced the issue and assigned it for an upcoming release. Not sure exactly when that will ship yet, but I will keep you posted.
Inspiring
August 17, 2016
We talked more about this and, unfortunately, there isn't a good answer because VR focus and keyboard focus are two separate things. If your app loses keyboard focus, it will also lose the mouse cursor lock, so you need to re-lock the cursor when you get keyboard focus back.
Up and Coming
August 25, 2016
Although that seems to be true it doesn't seem to happen when using the Vive, just the Oculus. I've also discovered another explanation relating to this which I've commented on in the ticket.

I've discovered that if you click on the outside of the window and then back in again that the mouse becomes locked again. I've also notice that the OnApplicationFocus function returns false even though it is focused until you've done this.

So Unity's own OnApplicationFocus falsely indicates whether the mouse is in focus or not.

I've added a mouse isn't in focus dialogue to my player so people know in the headset when the mouse is outside the area but this is just annoying most people.

If anyone can come up with any suggestions I'd be very greatful :)

Inspiring
August 25, 2016
There's a patch note in the latest patch release that might be applicable:

  • (803319) - Windows Standalone: Fix regression where "touch up" events would be lost when occurring outside window bounds.

Maybe a version update would help?
Inspiring
August 25, 2016
> I've discovered that if you click on the outside of the window and then back in again that the mouse becomes locked again

This should be the case for Rift and other VR headsets.

> 
OnApplicationFocus function returns false even though it is focused until you've done this.

There is a known issue where 
OnApplicationFocus gets called the same way for two different kinds of focus: keyboard focus and Oculus VR focus. It only gets called with true if the app has BOTH kinds of focus, but you can check OVRManager.hasVrFocus to see whether the app has Oculus VR focus.
Up and Coming
August 26, 2016
@vrdaveb Thanks for the info. I'll look into that.
@delphinius I'll also look into that. Although I'm currently stuck on 5.4.0f1 as there is a weird thing that happens with some of my objects disappearing fading out when move away from there. It's very odd and I can't find any information on it. Still, currently the version I'm on works so I'll stick to that :)
Inspiring
August 27, 2016
> weird thing that happens with some of my objects disappearing fading out when move away from there

That's odd, be sure to file a bug with Help > Report a bug.
Up and Coming
August 28, 2016
I'd like to file a bug report but currently I have no easy way of replicating it without providing my whole project. The objects that are fading are created at runtime using obj importer and I have a feeling that it's something to do with Unity the scale of the object and something getting confused and thinking the object is really far off and fading it out to cull. It's only a guess but the best I can come up with at the moment.