Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by FuryFight3r · Mar 31, 2020 at 11:22 AM · mouseescapeshows

Remove unitys standard 'ESC' Function Cursor - Windows

How do I disable the default function of Unity that Escape brings up the mouse.

As when I press escape it pauses the game, Freezes the character and movement and brings up a paused UI if I press Escape againto exit the pause menu the mouse disapears for a breif second and then pops back up, I do gain access to the player again, but for some reason the cursor will continue to display the mouse regarless if I set Cursor.visable = false;

Current code that handles pausing the game.

          if (isPaused && Input.GetKeyDown(KeyCode.Escape))
          {
              fpc.enabled = true;
              Cursor.lockState = CursorLockMode.Locked;
              Cursor.visible = false;
              pausedCanvas.SetActive(false);
              isPaused = false;
          } 
          else if (!isPaused && Input.GetKeyDown(KeyCode.Escape))
          {
              fpc.enabled = false;
              Cursor.lockState = CursorLockMode.None;
              Cursor.visible = true;
              pausedCanvas.SetActive(true);
              isPaused = true;
           }
Comment
Add comment · Show 4
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Bunny83 · Mar 31, 2020 at 02:25 PM -1
Share

You forgot to mention your target platform. If you talk about WebGL, there's no way to prevent that since pressing ESC is a security measure of the browser that you can not control or prevent. Any other platform shouldn't have this issue at all. If you're developing for WebGL you should find a different key to close a menu.

avatar image FuryFight3r Bunny83 · Mar 31, 2020 at 02:41 PM 0
Share

Sorry forgot to mention that, Windows and Linux

avatar image Bunny83 FuryFight3r · Apr 02, 2020 at 02:14 PM -1
Share

Are you actually testing in a build game? Or do you only test inside the Unity editor? The Unity editor has several hotkeys it reacts to even when in playmode / gameview. The Unity editor is there to design and edit your game. So all hotkeys in the editor are there to help the developer. I haven't made any FPS tests in the recent Unity versions so I can't tell if this is actually an issue in a build. The last time I made a fps demo was years ago and I can't remember any issues with the escape key.

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Bunny83 · Apr 03, 2020 at 11:40 AM

Ok since you put up an example (without any code) I decided to quickly boot up my Unity test project and throw together a minimalistic FPS setup. A single script on a character controller capsule. The main camera is simply a child of the player. This is the result after a windows standalone build

As you can see by pressing the ESC button when in the menu I just set Cursor.visible to false and Cursor.lockMode to "Locked". Everything seems to work as it should. Note that when testing inside the editor pressing the ESC button does not lock / hide the cursor again as mentioned in the comment above. However the build works as it should.


I used Unity version 2019.2.14f1. I'm on a Windows 10 64Bit machine (Intel i7 with a relatively old NVIDIA GeForce GTX 750 Ti).


I currently don't have a running linux machine (beside my Raspberry PI server with rasperian) so I can't test a linux build. I can not reproduce your issue. If you want any further help with your issue you have to provide much more information and much more details on your specific case.

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image FuryFight3r · Apr 03, 2020 at 12:11 PM 0
Share

If you had of asked for me to show the code, I would of happily supplied it then and there. but its as basic as you can get so I didnt think it would be neccesary.

         if (isPaused && Input.GetKeyDown(KeyCode.Escape))
         {
             fpc.enabled = true;
             Cursor.lockState = CursorLock$$anonymous$$ode.Locked;
             Cursor.visible = false;
             pausedCanvas.SetActive(false);
             isPaused = false;
         } 
         else if (!isPaused && Input.GetKeyDown(KeyCode.Escape))
         {
             fpc.enabled = false;
             Cursor.lockState = CursorLock$$anonymous$$ode.None;
             Cursor.visible = true;
             pausedCanvas.SetActive(true);
             isPaused = true;
          }

System: Win10 x64, Unity 2019.2.16f1, 16gb RA$$anonymous$$, i5 4460 3.2ghz, NVIDIA GeForce GTX 1060 6gb

Game: Using Unitys First Person Character with the pause script attached.

avatar image Bunny83 FuryFight3r · Apr 03, 2020 at 01:41 PM 0
Share

Well, is this snippet in Update and not in FixedUpdate or OnGUI or some other callback that doesn't run in sync with actual input frames? Also are you sure this is the only place in your entire project where you change the lockState and the cursor visibility? What's your used Unity version? You seem to use the old input system (like I do as well). However have you enabled the new (preview) input system?


Note that I don't need all this info since I'm not the one with the problem. You want your issue to be fixed and we invest our spare time trying to help you. Since you have that issue and I don't there has to be something different on your side. However we can only work with what you give us.

avatar image FuryFight3r Bunny83 · Apr 03, 2020 at 02:06 PM 0
Share

Yes this is the only thing in the entire project that enables and disables the mouse on pressing escape and Yes it is in Update() I tried FixedUpdate, but that sometimes wouldnt even open the pause menu, I did have other functions that closed opened UI's but had removed them to test if they were the issue, but still get the same result. I dont know what further information I can provide unless you let me know what it is you need.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

133 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How do I do this? 2 Answers

when I pause the game with "escape" and unpause the mouse apears on the screen with the fps controller 1 Answer

MouseDown Hold vs Release 1 Answer

input from mouse relative to screen dimensions- how to 1 Answer

Mouse Orbit - Change From Mouse, to Keys 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges