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
2
Question by sh_code · May 04, 2018 at 06:16 AM · cursorinterfaceinteraction

How to make cursor locked but active in Unity 2017?

I'm trying to have a world-space UI, and a FirstPersonController which should be able to interact with that UI via aiming reticle, basically meaning via (visible or invisible, not important to me) hardware cursor locked to the center of the screen (how Cursor.lockState = CursorLockMode.Locked does), but I still need it to dispatch events to UI elements, which CursorLockMode.Locked doesn't do

Firstly, how do I do this in any way?

Secondly, I assume all suggested answers will be more or less hacky, as all answers I found so far (which didn't work) were, so... in case a Unity employee will read this - there should be an easy and obvious way to do this, as well as a normal way to set cursor's position. To be honest, I'm very surprised there's no Cursor.SetPosition function (which would basically solve my issue as I would just be doing SetPosition(center of screen) at each frame).

OR, if I'm going about this the wrong way, what would be the right way to make Unity UI elements respond to custom-positioned reticle as if it were the cursor?

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 Harinezumi · May 04, 2018 at 07:40 AM 0
Share

Thank you, finally someone else has the same issue! While I understand that there are certain limitation, a locked cursor should still allow clicks (and not hide the cursor), OR it should be possible to dispatch events to the UI from code. Alas, it is not so.

About positioning the cursor, if I remember correctly there is no Cursor.SetPosition(), because it is platform dependent and it was just not possible on $$anonymous$$acOS (the cursor is controlled by the OS)., and the concept of cursor doesn't make much sense on touchscreens.
However, on Windows you can import some DLLs (I don't remember the names) that lets you set the cursor position. This is quite easy and works relatively well.
On other platforms the only possibility I can think of is that you hide the cursor ( Cursor.visible = false) and implement your own cursor to be exactly where the invisible cursor is. To be honest, I was not able to achieve the exact positioning, but it should be possible.

avatar image sh_code Harinezumi · May 04, 2018 at 07:45 AM 0
Share

"However, on Windows you can import some DLLs (I don't remember the names) that lets you set the cursor position. This is quite easy and works relatively well."

what you mean is this http://answers.unity.com/answers/1265069/view.html

which I haven't tried because to me it counts as the hackiest solution of all, even few notches above overriding the StandaloneInput$$anonymous$$odule.

"because it is platform dependent and it was just not possible on $$anonymous$$acOS (the cursor is controlled by the OS)., and the concept of cursor doesn't make much sense on touchscreens."

irrelevant. didn't stop anyone from implementing the existing cursor functionality for platforms where it makes sense ;) (i understand what you mean, and I disagree with the point which you are using this as a support argument for)

avatar image Harinezumi sh_code · May 04, 2018 at 08:02 AM 0
Share

Yes, that is the answer, and I agree that it is horribly hacky, I would not have suggested it if I knew of a better solution (and probably being influenced by finding it during the development of a project where I was required to move the mouse cursor on Windows with an xbox controller :O ).

I wasn't supporting the lack of SetPosition(), just giving the reason why (as far as I know) Unity Technologies didn't implement it. I don't see why not implement such a useful feature for platforms where it makes sense.

Anyway, let's hope something useful turns up :)

avatar image sh_code Harinezumi · May 04, 2018 at 07:46 AM 0
Share

in any case, I'm happy to know I'm not alone in this :) let's see what answers we get :)

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by NoDumbQuestion · May 04, 2018 at 08:15 AM

@sh_code @Harinezumi You can create a custom cursor for UI mouse event when Cursor.lockState = CursorLockMode.Locked.

You could use Input.GetAxis for MouseX and Mouse Y as they represent mouse movement.

Or for advance method you could have update() method for Event.current to get real mouse delta position.

PS: Change your name sh_code. @ notification not work with your name.

Comment
Add comment · 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

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

84 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

Related Questions

How to make binary array toggle,How to make binary array switch/toggle? 0 Answers

Permanently Delete Assets from Project View 2 Answers

Picking Interactive Cloth Verts In Game 0 Answers

No Buttons Click when Play Exported WebGL version of the Game 0 Answers

Pick up game objects with cursor (raycasting) 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