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 InputSystem reporting wrong mouse position after WarpCursorPosition

Discussion in 'Input System' started by Garrafote, Jul 10, 2020.

  1. Garrafote

    Garrafote

    Joined:
    Jun 13, 2013
    Posts:
    48
    I noticed that when calling Mouse.current.WarpCursorPosition() the cursor will move to the right position but InputSystem will report the old position until the next mouse event.

    This is happening on:
    Input System 1.0.0
    Unity 2020.1.0b14
    Windows 10
     
    rboerdijk likes this.
  2. Garrafote

    Garrafote

    Joined:
    Jun 13, 2013
    Posts:
    48
    If someone else anyone finds this bug, I managed to work around this by manually queuing a state event:

    Code (CSharp):
    1. Mouse.current.WarpCursorPosition(focus);
    2. InputSystem.QueueDeltaStateEvent(Mouse.current["position"], focus);
     
    Last edited: Jul 10, 2020
    rboerdijk and donkey0t like this.
  3. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    9,913
    This is not a bug. It is a documented behavior.
     
  4. Garrafote

    Garrafote

    Joined:
    Jun 13, 2013
    Posts:
    48
    @Lurking-Ninja

    Thanks for pointing that out, but I'm aware of the documentation and it still fells like a bug.

    See, the documentation states that "the position property will not update immediately but rather will update in the next input update". This means that the position should be updated on the next frame's Update, or isn't that right?

    Well that is not what I'm getting.
    As I said, the position property is only updating after another mouse input event, In other words, the mouse pointer will - by default - only be warped to the target position after the mouse is physically moved or clicked.
     
  5. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    9,913
    You just highlighted it bold. When the input next updates. Update method and input update aren't the same thing, the input doesn't even need to update in the Update method.

    But if you still feel it's a bug, why don't you report it instead of the forum? But again, it is documented behavior so...
     
  6. Zelgadis87

    Zelgadis87

    Joined:
    Nov 14, 2016
    Posts:
    6
    This was driving me crazy too. I read the documentation and thought in the next frame update it would read the correct position, I didn't understand it would *only* update on the next input event. Thanks @Garrafote for the heads up!
     
  7. dmytro_at_unity

    dmytro_at_unity

    Unity Technologies

    Joined:
    Feb 12, 2021
    Posts:
    212
    Position should be updating next frame / next update, I've checked and what we're doing at warp is calling SetCursorPos / CGWarpMouseCursorPosition / SDL_WarpMouseInWindow / etc, and code relies on OS to report the new position as-it-would-be for normal user mouse movements, but maybe that is not happening at all.

    Could you please report it as a bug (Help->Report bug) and we will take it from there. Thanks a lot!