Strange bug causing game window to lose focus

An odd bug recently popped up in the current game I’m working on: sometimes when I click any mouse button while testing the game in the editor’s game window, the cursor reappears, the game window loses focus, and I can no longer interact with the game until I click on the game window again. This started happening while I was changing some of the code which processes mouse button input, but I didn’t change anything that would cause something this drastic. Is there a known bug which causes this?

I isolated the problem to a loss of cursorlock, which sometimes happens when clicking the mouse button and temporarily happens when moving the mouse (in which case the cursor flickers back and forth between the middle of the game window and outside the game window, as if it’s temporarily losing lock and then being locked again). I’ve read that when running a game inside the editor, cursorlock isn’t handled properly; so is this a known bug or is it due to something else? I can’t find anything in my code that would cause it.
{Edit: I finally found other forum posts on the same problem, such as: Cursor Lockstate Troubles - Unity Engine - Unity Discussions ]
I’m using 5.0.1

Hi, this is indeed a bug that’s still occurring (see the public issue tracker case.) I’ll reach out to the team to hear what’s going on as it’s a bit misleading that it is marked as “Fixed” in Issue Tracker.

1 Like

Thank you. Is there a feasible workaround?

So after chatting with the team, the symptom in the issue I linked earlier could be the same but different cause, so they will still need a bug report so they can get information like OS, gfx card, and more from the bug reporter. The issue I linked is supposed to be fixed in 5.1 if you want to give it a shot, but still seems to show up for some users in version of Unity 5.1 and later. Perhaps upgrading will solve it in your specific case?

1 Like

Thank you. Upgrading wouldn’t help if it will still be a problem for some end users (I’m working on software I’m hoping to sell). I can submit a bug report since it seems to be a different problem - it isn’t just the cursor flickering, but rather the cursor also doesn’t remain locked.

Ahh okay, makes more sense then with a report!