Forum Discussion
Epineurien
9 years agoHonored Guest
Cursor Lock unavailable ?
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.
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.
- 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
Replies have been turned off for this discussion
- vrdavebOculus StaffUsing 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.
- EpineurienHonored GuestRecommended or not, this behavior is still clearly a bug.
Anyway, I used the gaze-based system from this user "https://forums.oculus.com/developer/discussion/16710", since it doesn't require to modify all UI components - so problem solved. - philedayMHCP MemberI'll like to chip in and say I've also experienced this same issue. My UI system allows for crosshair gaze but if people move the mouse they can use the mouse to control the UI if they like, hopefully best of both worlds. However as stated it keeps unlocking the mouse and causes people to click out of the window. This does feel like a bug. I can change my Unity project to not use the Oculus SDK and just use the openVR and it then works. However this causes other issues.
I don't want to avoid using the Oculus SDK but with this issue I can't see a solution apart from using OpenVR. Is there a work around or any chances of an update?
All the best
Phil - vrdavebOculus StaffI believe this is intended behavior, but I agree it's weird and there are still cases where you want to capture the mouse instead of clicking on random things on the Windows desktop. I've pointed it out to Unity. In the meantime, you could potentially use SetCursorPos(..) to force the mouse to a safe position. You will have to DllImport it from User32.
- philedayMHCP MemberThank you. I'll give that a go. Hopefully there is some solution to this in the future :)
- philedayMHCP MemberOK, I've managed to get the mouse cursor control working however I still have a problem. I can't get the centre of the Unity app window. So I don't know where to position the mouse. Here is my code so far.
using UnityEngine;
using System.Collections;
using System.Runtime.InteropServices;
public class MouseCentre : MonoBehaviour {
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern int SetCursorPos(int x, int y);
void Update(){
SetCursorPos(Screen.width / 2, Screen.height / 2);
}
}
Any suggestions? - vrdavebOculus StaffYou need to account for the window's position. Maybe use FindWindow and GetWindowPos?
- philedayMHCP MemberI'm not that versed in C Sharp so had difficultly with finding the window location. I've found another problem with my original code and thats that although it drags the cursor back to the centre, it only does this on the updates (I'm guessing) which actually allows you to get out the window by moving the mouse quickly, not even that quickly. I guess I'm going to have to wait for a proper fix or if any good coders out there come up with a solution/workaround.
I really hope they update this soon, it's a real problem for Whirligig (my program) and having native Oculus support. - vrdavebOculus StaffUnity is looking at this, but so far they have been unable to reproduce it. Can you click Help > Report a bug... and share the case number it sends you here? That will give them easier steps to reproduce the issue.
- philedayMHCP MemberSorry I'm a little confused. You said earlier 'this is intended behavior'. Are you referring to the cusor.locked? I've posted the bug report. It's pretty easy to recreate. Simple put, Cursor.lockState = CursorLockMode.Locked; works in OpenVR on Oculus and doesn't work using Oculus on Oculus in Unity.
Quick Links
- Horizon Developer Support
- Quest User Forums
- Troubleshooting Forum for problems with a game or app
- Quest Support for problems with your device
Other Meta Support
Related Content
- 2 months ago
- 4 months ago