Has anybody so far succesfully used cursor lockstate and visibility in Unity 5? For me, it doesn't seem to work reliably. The code I use is: Code (CSharp): Cursor.visible = false; Cursor.lockState = CursorLockMode.Locked;
I've already reported this bug, they confirmed and said it will be fixed... but couldn't tell me when or what version. I tested and reported with b11 btw.
What exactly was that bug about? I was fighting with the cursor lock and finally came up with this piece of code: Code (csharp): private void Update() { if (cursorShouldBeLocked) { Cursor.lockState = CursorLockMode.Locked; Cursor.visible = false; } else { Cursor.lockState = CursorLockMode.None; Cursor.visible = true; } }
Yea, this is still broken in B18. Alexzzzz's solution kinda works in editor, but mouse position seems to be wrong as clicking loses focus on game window and it doesn't work outside editor. I'd also wager it'd be bad if this had to be done every update, certainly shouldn't need to be and didn't need to be previous to U5.
That does not fix the problem. The editor often un-hides the cursor on it's own and even using that code once per frame it flickers back over my screen. I've noticed the the cursor resets position to the Scene View editor on my monitor #1, while my game view is on monitor #2. It's very broken, even not coming back after setting Cursor.visible = true and lock state to none. As I said, I reported back on b11 some time ago. And they said they were going to fix it, but not when. Sad that it still exists two months later. As another note, the first time you do it seems to stay hidden/locked. However, after a few toggles it breaks and internal state seems corrupt/out of sync.
Still not working properly as of b21 - it's really annoying, it's clicking anywehere randomly, going off screen
Yea, I noticed that setting the lock state property, even if it's not changing, will change the cursor focus to a new window. Seemingly, there's some code run in that property setter that's likely looking at the last drawn window and locking to that, since it seemingly will jump to a window that redraws per frame (for me, profiler and animator, never project or inspector). They really need to fix this though, it's pretty damn crippling for testing my project.
I no longer see the cursor flickering in b22. I'm still using the code from my earlier post. I worked fine in standalone builds, but there was flickering in the editor. Now everything looks fine.
I managed to get around it in cooked build. I set the cursor texture as a totally transparent GUI texture. Even if it flickers, it's invisible anyway.
Has there been any progress on this? Someone had submitted a ticket for it, right? I'm setting locked or unlocked every frame since that's the only way to get remotely playable behavior but the cursor is flickering and sometimes gets locked at the lower left of the screen instead of the center. Arg!
I didn't had a repro case, this was what I sent them : 1) What happened This code : Cursor.lockState = CursorLockMode.Locked; Cursor.lockState = CursorLockMode.None; Do not work. Sometimes they do, most of the times they don't. It's impossible to center the mouse in the screen, and unlock it to go to a menu, and lock it again to go back to the game. See aditional posts by other users : http://forum.unity3d.com/threads/locking-the-mouse.294453/#post-1941423 http://forum.unity3d.com/threads/cursor-lockstate-troubles.278221/