• 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 /
  • Help Room /
avatar image
Question by somefsafa · Sep 27, 2021 at 08:31 PM · unity 5camerainputmousemouseposition

Mouse position from new InputSystem is not correct and is not the same as Input.mousePosition

Hello Unity community,

I've migrated to UnityEngine.InputSystem package and have had mouse position problems ever since.

When I create a new 2D project and add a simple script with

 using UnityEngine;
 
 public class MouseInputTest : MonoBehaviour {
 
     void OnDrawGizmos() {
         var mousePosition = Input.mousePosition;
         Gizmos.DrawCube(Camera.main.ScreenToWorldPoint(mousePosition), Vector3.one);
     }
 }
 

All works as expected and the gizmo is shown correctly at the mouse position.

However if I import the InputSystem package and use the following code

 using UnityEngine;
 using UnityEngine.InputSystem;
 
 public class MouseInputTest : MonoBehaviour {
 
     void OnDrawGizmos() {
         var mousePosition = Mouse.current.position.ReadValue();
         Gizmos.DrawCube(Camera.main.ScreenToWorldPoint(mousePosition), Vector3.one);
     }
 }
 

The Y coordinate of mouse position vector (Mouse.current.position.ReadValue()) is inverted (for example it's value is 10 instead of -10). And X coordinate seems offset by camera width to the left.

T$$anonymous$$s is all with default project settings. Any idea why t$$anonymous$$s happens? Am I doing somet$$anonymous$$ng wrong? Couldn't find any help in the forums or documentation.

I guess it can be "fixed" by manually inverting the Y and offsetting X, but it seems weird.

Any help is appreciated.

Comment
Cawotte

People who like this

1 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 somefsafa · Sep 27, 2021 at 08:35 PM 0
Share

alt text

screenshot-2021-09-27-at-223307.png (83.2 kB)

1 Reply

· Add your reply
  • Sort: 
avatar image

Answer by Cawotte · Sep 24, 2022 at 05:38 PM

Hello,

T$$anonymous$$s is an answer coming one year too late, but I racked my brain over the same issue for almost two days, and your post is the only one I found describing the same problem than I had, or actually, still have, but worked around. Hoping t$$anonymous$$s will help other people stumbling on it.


The mouse position in the new Input System is simply incorrect when using the Scene tab. Comparing values with before and after the transition, it is inverted, and using the Scene screen size as a distance reference w$$anonymous$$le using the corner of the Game tab as the starting point, resulting in a non-sensical offset, heavily depending on how you placed and sized your two tabs.

However, it is actually possible to displays Gizmos in the Game tab. In the toolbar of the tab there's an option to set it on, the Gizmos drawn here are correct, and use the proper values.


Why the gizmos are not working properly in the Scene view is beyond me, it's baffling that two years after being available, the new package still don't have a basic feature like t$$anonymous$$s nailed down. It makes the upgrade to the new system feel like a downgrade, and very infuriating as an user trying to get onboard with what are supposed to be the new better tools. At least there exist the work-around of looking at the gizmos from the Game tab, but there shouldn't even be a need for that in the first place.

Comment

People who like this

0 Show 0 · 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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

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

Please help me with my mouse pointer 0 Answers

Bullet to Mouse Position? 1 Answer

How do I draw a raycast with my mouse position that is relative to the main camera? 0 Answers

How to control global mouse 0 Answers

Issue with mouse input when locking the cursor 2 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