Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 misabiko · Jul 18, 2020 at 01:16 AM · cursorpackageslock-cursor

CursorLockMode.Locked doesn't hide if cursor hovers the editor

I'm trying to capture the cursor to play in first person, but when I use Cursor.lockState = CursorLockMode.Locked the cursor gets locked to the center but is still visible, which I don't want.

It took me a while to figure out what was going wrong, I must have my cursor hover the "Game" editor window, only then will the cursor be hidden, otherwise it only gets locked. When running from a build it works without issue.

My question is can I fix this, where I wouldn't have to keep my cursor on the game window?

I had the same issue on 2019.4.3f1 and 2019.4.4f1.


EDIT: I just tried to create a couple new projects on 2019.4.3 and 2019.4.4, and I think my problem is with either the packages or the template I'm using.

I made a custom template (alternative to 3D or "3D With Extras"), basically "High Definition RP" but with less cluther in the assets and with InputSystem and Cinemachine.

I created an extra project with that template, and added a single script with Cursor.lockState = CursorLockMode.Locked in Start(), and it had the same problem.

I then created two more projects on 2019.4.3 and 2019.4.4, using the regular 3D template, and it worked as it should, the cursor gets captured no matter where the cursor is.

I did have issues on this template with Cinemachine not having a menu at the top, and I had to remove and re-add the package to fix this, so this might be something similar with another package.


EDIT2: I narrowed down the issue to InputSystem, if I create a brand new project, install InputSystem and set the Active Input Handling to Input System, it will reproduce the error. I tested it on 2020.1.f1 and 2019.4.4f1, with template 3D and URP. Setting Active Input Handling to Both seems to fix the issue.

I also sent a bug report.

I found a forum thread which describe pretty much the same issue, but the bug report linked to is slightly different (Says locking doesn't work and only on the Player).

Comment
Add comment · Show 7
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 Acdia · Jul 18, 2020 at 03:42 PM 0
Share

I'm not sure if this is what you need but there is Cursor.visible = false; At least I use it always and had no problems.

avatar image misabiko Acdia · Jul 18, 2020 at 04:48 PM 0
Share

I forgot to mention that I did try Cursor.visible, when I start the game hovering the "Game" window, it works normally, but when I'm hovering somewhere else Cursor.visible = false has no effects.

Which makes sense because the Unity docs mentions Cursor.lockState = CursorLock$$anonymous$$ode.Locked sets visible to false by itself.

avatar image Miaw666 · Jul 18, 2020 at 05:13 PM 1
Share

I'm not really sure what you mean by "hover". The code should work by itself. I'm not sure, but I think it could be that you think it's not working because you're just trying the game in the unity editor. The mouse locking doesn't function the same way when you build the game (It's not a problem or a mistake, it's just to help you edit the game better).

Try building the game and trying it out, if you still think it's not working as you want, then there's a problem. Otherwise, it's just because you're technicality still in the editing process of the game.

avatar image misabiko Miaw666 · Jul 18, 2020 at 05:29 PM 0
Share

By hover I mean, I usually use the standard editor layout, with Hierarchy on the left, Game and Scene in the center, Project and Console at the bottom, etc, and when I launch Play $$anonymous$$ode, the editor buffers for a second and then launch the game, where my cursor should disappear and I'm able to control the game. However, with this issue, if my cursor is over the Hierarchy, the Inspector, the Console or anywhere that's not the "Game" window while the editor buffers, the cursor will only get centered on the "Game" window but still visible. If the cursor is hovering the "Game" window, everything goes on as normal.

But as I added in an edit, I'm pretty sure the problem is with one of my packages. Creating a new project with the "3D" template did not replicate the issue, but if I create one with my custom template, the issue is still there.

avatar image Miaw666 misabiko · Jul 18, 2020 at 06:22 PM 0
Share

So you mean, it works normally but if you move the mouse, even while the cursor is in the center and invisible, if you move it enough it will get over the other windows and the locking of the cursor will stop? You mean that it stops locking, but do you press escape or something like that?

Sorry my brain is half dead so I'm not getting what's happening exactly

Oh and where do you have the "Cursor.lockState = CursorLock$$anonymous$$ode.Locked"?

Show more comments

0 Replies

· Add your reply
  • Sort: 

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

132 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

Related Questions

Is There a Way to Lock the Cursor to a certain Axis? 1 Answer

Issues with mouse input when locking the cursor 0 Answers

Mouse cursor doesn't lock Unity 5 0 Answers

How can I change cursor visibility and cursor lock state when I press tab then revert it back when I press tab again. 1 Answer

How to move my cursor to a specific position and then lock it to that position. 0 Answers


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