Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
2
Question by soxroxr · May 25, 2016 at 02:46 PM · cursorcenterlock-cursor

Cursor not locking to center

I don't know why this is happening and I can't figure it out.

I'm using Cursor.lockState = CursorLockMode.Locked; and Cursor.visible = false; to lock it, and Cursor.lockState = CursorLockMode.None; + Cursor.visible = false to unlock it when I open a menu. It seems that setting the visibility is redundant but I wanted to be sure.

This is how I want it to behave, in game you get a crosshair, in menu you get the mouse. The problem lies when I pull up the menu and call it to lock again - it does lock, but it locks in the last position. I'm sure there's a not-so-problematic way to center the mouse on the screen but the documentation explicitly states that Cursor.lockState = CursorLockMode.Locked; "Lock[s] cursor to the center of the game window."

Is this a bug?

And for the sake of it, how would you move the mouse to the center? If I could get it there the lock would be fine. Is there a method for it? Would you have to get the screen width and height in pixels and divide by 2 like with some old OnGUI stuff, or is there a better way?

Comment
Add comment · Show 1
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 lodendsg · Jan 08, 2017 at 08:04 PM 1
Share

This seems to be bugged in Unity 5.5

in prior versions it was my experience that it did lock to centre of the screen and would still give you pointer events however in 5.5. I have noticed that it seems to lock to lower left of the screen or elsewhere. I have also noticed that when locked and hidden its not sending events save for click event ... I am not sure if this is a bug or intended ... I hope its a bug as it would make zero since why they would remove an obviously critical feature for many game types e.g. use centre of screen as cursor position hiding the pointer its self which previously was as simple as hide cursor, lock cursor.

As to moving the cursor sadly Unity doesn't expose this that I am aware of, there are a number of assets that allow you to do this though. I would love to hear from Unity on how we lock the cursor to the centre of the screen and how we get pointer events to keep working with a hidden cursor ... I really hope this a simple bug and not intended functionality.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Hiding a Cursor? 3 Answers

Cursor Lockmode only works once? 1 Answer

Cursor won't stay locked in update!! 0 Answers

Locking cursor/mouse on an object 1 Answer

FPS Controller Mouse not locking consistantly 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