Search Unity

Bug Mouse delta values LARGE when toggling Cursor.lockState

Discussion in 'Input System' started by EMOTION-THEORY, Jun 4, 2023.

  1. EMOTION-THEORY

    EMOTION-THEORY

    Joined:
    Jul 16, 2013
    Posts:
    83
    I have searched and searched to no avail, so here is my post --

    The issue:
    When going from mouse input on the screen (to control my UI) back to no mouse input (to control my avatar), my mouse delta reading is abnormally large, causing the first frame of camera movement to be massive and jarring (doing 180 turns, etc).

    It seems like when going from Cursor.lockState None to Locked, however far the mouse is from the center is what will be the delta in that first frame.

    What is EXPECTED BEHAVIOUR is that when I set Cursor.lockState to Locked and return to controlling my avatar, that it is as if the mouse is returned to the center, and the first frame of input will read the deltas as usual.

    The context:
    I am trying to toggle between my first-person controls and inventory screen UI controls. I am using the new Input System. My controls are driven by Unity events (not sure if that matters).


    The code:
    Here is a code snippet:

    Code (CSharp):
    1.        
    2. public void SetUIMode(bool uiState)
    3.         {
    4.             if (uiState)
    5.             {
    6.                 Cursor.lockState = CursorLockMode.None;
    7.                 playerInput.SwitchCurrentActionMap("UI");
    8.             }
    9.  
    10.             if (!uiState)
    11.             {
    12.                 Cursor.lockState = CursorLockMode.Locked;
    13.                 playerInput.SwitchCurrentActionMap("Avatar");
    14.             }
    15.         }
    16.  
    How can I solve this?
    I'm sure I can't be alone in experiencing this :(