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 Mouse delta values LARGE when toggling Cursor.lockState

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



    Jul 16, 2013
    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):
    2. public void SetUIMode(bool uiState)
    3.         {
    4.             if (uiState)
    5.             {
    6.                 Cursor.lockState = CursorLockMode.None;
    7.                 playerInput.SwitchCurrentActionMap("UI");
    8.             }
    10.             if (!uiState)
    11.             {
    12.                 Cursor.lockState = CursorLockMode.Locked;
    13.                 playerInput.SwitchCurrentActionMap("Avatar");
    14.             }
    15.         }
    How can I solve this?
    I'm sure I can't be alone in experiencing this :(