Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Bug Warping cursor affects mouse position/delta differently between platforms

Discussion in 'Input System' started by florianveltman, Sep 17, 2022.

  1. florianveltman

    florianveltman

    Joined:
    Sep 7, 2012
    Posts:
    27
    Hi all,

    Using the InputSystem version 1.3.0 (Unity version 2022.1.6f1), I encounter a problem using
    Mouse.current.WarpCursorPosition(targetPosition);
    .
    The way the cursor's position is updated varies between MacOS and Windows.
    On Windows, the cursor does move properly and everything is running as intended, however on MacOS, the cursor is only warping after moving the mouse.

    I have set up this little example script to test the problem:
    Code (CSharp):
    1. private void Update()
    2. {
    3.     if (Mouse.current.leftButton.wasReleasedThisFrame)
    4.     {
    5.         Vector2 position = Mouse.current.position.ReadValue();
    6.         Vector2 mirrorPosition = new Vector2(Screen.width - position.x, Screen.height - position.y);
    7.  
    8.         Mouse.current.WarpCursorPosition(mirrorPosition);
    9.      
    10.         Debug.Log($"warping mouse from {position} to {mirrorPosition}.");
    11.     }
    12. }

    When running the script on Windows, the cursor warps to a mirrored screen position from where the user has clicked. Clicking a second time without moving the mouse warps the cursor again, back to the original screen position.
    On MacOS however, the cursor does warp to the new position, but if the user clicks again without moving the mouse, the Debug.Log message shows that the cursor's position has not been updated. Visually, the mouse doesn't appear to move at all.

    After googling for answers, I came across the use of
    InputState.Change(Mouse.current.position, targetPosition);
    , which I think helps with my implementation but doesn't help to circumvent the issue highlighted by the above example script.

    I am looking to have a feature parity between Windows and MacOS, and hope to find a way to force update the cursor's position so that I can use the WarpCursorPosition() function the same way across platforms.

    Any help or tips getting this to work are very welcome!
     
    Last edited: Sep 19, 2022
  2. florianveltman

    florianveltman

    Joined:
    Sep 7, 2012
    Posts:
    27
    For info, it appears as though the OS actually reports the correct position. Using
    Cmd + Shift + 4
    to check the cursor's coordinates, it updates properly immediately after the warp.
    I think this indicates that the new position isn't being registered properly by Unity.

    Another interesting detail: in the example script I posted above, the cursor does eventually warp again when clicking multiple times without moving the mouse, it just takes several seconds for the cursor position to be updated internally.

    I'll upload a couple of screen recordings to highlight the issue later on.
     
  3. florianveltman

    florianveltman

    Joined:
    Sep 7, 2012
    Posts:
    27
    Here is a screen capture of the example code from the first post, running on Windows:
    warp cursor position windows.gif

    And here is the same setup running on MacOS:
    warp cursor position mac.gif

    As you can see, on Windows the cursor is being warped properly the second time as well. On MacOS, as the position is determined by an offset from the current cursor coordinates, the second click doesn't warp the cursor, indicating that the cursor's position is not set internally.

    Based on the following thread: https://forum.unity.com/threads/mou...se-delta-on-linux-but-not-on-windows.1268516/
    I suspect that this issue is also present in Linux, and only works correctly on Windows (if reporting the new position as the cursor's position is the intended behaviour).

    The following thread appears to report the same issue back in version 1.0.0 for Windows: https://forum.unity.com/threads/inp...use-position-after-warpcursorposition.929019/
    The solution the author of the thread proposes doesn't seem to work in my situation.

    Any help, workaround or suggestion is greatly appreciated!