Not too sure how to ask this, I'll try my best.

Currently, I'm working on a First-Person Controller. I'm adding functionality for a pause menu so that when you press escape, it will open the pause menu, unlock the cursor, and make it visible. If you press escape again, while the pause menu is open, it will do the opposite: hide the cursor and lock it again.

The problem I'm running into is that Unity already kind of does this. It doesn't matter if you're in the editor or if your game is built: whenever you press escape, it will unlock the cursor and show it, so you can exit the game (in a built application) or get out of play mode (in the editor).

I'm 99% sure this is Unity's default functionality. I have looked in Unity itself and haven't found a way to turn it off, and I have also looked online. Any help would be greatly appreciated.


2 Answers 2


If you are using Unity's FPSController then this post might have the solution https://forum.unity.com/threads/how-to-disable-escape-key-to-unlock-the-cursor-fix.511674/

If the forum post does not solve your problem, the error probably lies in your own escape code triggering twice (or fails to set the correct value). Edit: in that case please provide your code.

According to the documentation https://docs.unity3d.com/ScriptReference/Cursor-lockState.html the unlock on escape should only happen in editor.


This seems to be a problem related to the code in Unity's standard assets: In order to lock the cursor, you would set the CursorLockMode to Locked;

Your FPSController script (or whatever script is attached to your player) is checking wheather the "escape" key is pressed and setting the cursor mode to None by doing:

    Cursor.lockState = CursorLockMode.None; // free the cursor

Contrarily, when pressing the left mouse button (also known as "mouse button 0"), it's setting the cursor state to locked:

    Cursor.lockState = CursorLockMode.Locked; // lock the cursor

If you don't want this code to be managed within the fps controller (which i assume you don't, given the situation), you just need to remove the bit of code where the cursor lockState gets changed from the FPSController script;

This obviously also applies if you are not using the standard assets.
This is not Unity's standard behavior, so i suggest you look for any eventual script that might be modifying the cursor lockState.

  • \$\begingroup\$ Unfortunately, even with, say, a static camera (with no scripts, etc.) it still happens. Thanks for the help though. \$\endgroup\$ Commented Jan 30, 2019 at 23:24
  • 1
    \$\begingroup\$ @ThriftyDonut how are you locking the cursor without any scripts? \$\endgroup\$
    – DMGregory
    Commented Jan 31, 2019 at 1:20
  • \$\begingroup\$ @DMGregory I'm not, but Unity still unlocks and shows the cursor when I press escape and relocks and hides it when I click in the play area. \$\endgroup\$ Commented Jan 31, 2019 at 1:30
  • \$\begingroup\$ Then you have code somewhere. We can't find it for you because we're not clairvoyant. \$\endgroup\$ Commented Jan 31, 2019 at 18:27
  • \$\begingroup\$ @Draco18s It happens even in an empty scene, with just a camera. It's Unity's default functionality. \$\endgroup\$ Commented Feb 8, 2019 at 21:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .