Mouse.WarpCursorPosition moves cursor to incorrect location

I’m trying to save the cursor location and move it back when the user right clicks and drags, I have an input action set up for right click, that performs the following code:

public void OnRotationModifier(InputAction.CallbackContext ctx) {
    var rotate = (int) ctx.ReadValue<float>() == 1;
    if (rotate) {
        _lastMousePos = Mouse.current.position.ReadValue();
        Debug.Log("Rotate " + _lastMousePos);
    }
    else if (_lastMousePos != Vector2.zero) {
        Mouse.current.WarpCursorPosition(_lastMousePos);
        Debug.Log("Unrotate " + _lastMousePos);
        _lastMousePos = Vector2.zero;
    }

    Cursor.visible = !rotate;
    _rotating = rotate;
}

I get the same values printed:

Rotate (734.0, 417.0)
Unrotate (734.0, 417.0)

Yet the cursor goes to the completely wrong part of the screen almost every time. I can’t tell if I’m doing something wrong or if this is a bug. Any help would be appreciated.

Perhaps adding a normalize processor will help? I was getting wonky results until I normalized it via the input system.

Also I would say maybe try getting the delta instead of position, as this has helped me in the past.

I am using deltas for the movement part, this is just to check whether the player has pressed the button to start rotating, as I wanted it to be customizable instead of just checking for RMB. The rotation part itself works flawlessly, I just don’t want to use CursorLockMode.Locked as it moves the cursor to the center every time.

Probably it works when doing Build & Run, but it doesn’t work in the editor?
If so, try Screen.height - mousepos.y for the y-coordinate, before passing in into WarpCursorPosition:

#if !UNITY_EDITOR
// bug workaround : Mouse Y Position Inverted in Build using Mouse.Current.WarpCursorPosition
mousepos.Set(mousepos.x, Screen.height - mousepos.y, mousepos.z);
#endif