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.

This is all with default project settings. Any idea why this happens? Am I doing something 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.

Hello,

This 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 this 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 while 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 this 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.