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 Nathan7 · Sep 01, 2011 at 10:32 PM · uiguimousemousemove

Capturing Mouse Position w/o Polling Every Update?

Hey everyone,

For my GUI, I'd like to use keep track of the mouse position while avoiding simply polling for the position every Update(). Ideally, I'd like to leverage the "mouseMove" event since then I can unnecessary code execution when the mouse position hasn't changed, but the mouseMove Event isn't fired in game (only the editor, see http://unity3d.com/support/documentation/ScriptReference/EventType.MouseMove.html).

Does anyone have a good workaround for this problem? Is there a efficient, standard way to capture mouse position that I'm just overlooking?

Thanks,

Nate

Comment
Add comment · Show 3
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 by0log1c · Sep 01, 2011 at 10:40 PM 2
Share

I can't help but wonder if this isn't a little overkill? A simple Input.mousePosition poll once a frame probably isn't noticeable I$$anonymous$$HO (is it?). I'm interested in any performance improvement this thread might bring but my two cents is 'just get it if you need it' :)

avatar image Waz · Sep 01, 2011 at 11:27 PM 2
Share

I agree with BY0LOG1C. If your problem is a high-cost operation you need to do each move, then compare position to last frame and avoid the operation when zero change, but just the call to get the mousePosition is immaterial compared to everything else you need to do every frame.

avatar image Talimar · Sep 01, 2011 at 11:33 PM 1
Share

What Warwick said needs to be made the answer. This is such an insignificant use of resources and you have far bigger things to worry about.

3 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by Waz · Sep 02, 2011 at 12:41 AM

Since your problem is a high-cost operation which you need to do each move, solve this by comparing the mousePosition to what it was in the previous frame and avoid the operation when the change is zero. The actual cost of reading mousePosition is immaterial.

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
avatar image
0

Answer by SinisterRainbow · Aug 14, 2013 at 09:24 PM

This is an old question, and I agree with the answer: but there is another work around that may work for some: events are fired during MouseDrag you can catch. Read the docs on it if appropriate for you.

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
avatar image
0

Answer by rocifier · Apr 28 at 10:23 AM

Update: There is now a new Input System package which could do this more generically without code.

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

8 People are following this question.

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

Related Questions

Mobile controls, gui mouse problem. 0 Answers

4.6 UI Image follow mouse position? 4 Answers

Procedurally generated uGUI elements render under world space objects 1 Answer

(4.6 UI) How to highlight a character/unit when moused over? 1 Answer

Where do I find UI Text? 3 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