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.

Bug Input System delta[mouse] add values on click or any mouse button pressed

Discussion in 'Input System' started by valentin56610, Apr 15, 2022.

  1. valentin56610

    valentin56610

    Joined:
    Jan 22, 2019
    Posts:
    151
    Hello there,

    I am switching over from the old input system to the new one and I got stuck with an annoying bug.

    I basically have the same issue as here : https://forum.unity.com/threads/input-system-delta-mouse-add-values-on-click.851794/
    But it seems nobody cared to fix that since 2020!

    Whenever I poll the mouse delta to move my camera in my Update() function, if I press any button on the mouse I get completely f* up random values
    The mouse is NOT moving at all

    I only have this in my code : Vector2 cameraInput = Mouse.current.delta.ReadValue();

    Video showing the bug and showing the console as well debugging the polling right after reading the value:


    In this video all I'm doing is moving the mouse around OR left clicking, right clicking, or using the scroll
    When right clicking, left clicking, or using the scroll this registers as a delta change and therefore moves my camera

    Please, somebody shed some light on this as this just killed my camera system and my game is now on hold.

    Edit : Just tested in 2021.3.0f1 LTS same results.

    MacBook Pro 16 M1 Pro
    MacOS 12.3.1
    Unity LTS 2020.3.33f1
    Input system package 1.3.0
     
    Last edited: Apr 15, 2022
  2. valentin56610

    valentin56610

    Joined:
    Jan 22, 2019
    Posts:
    151
    So, just in case anyone here is doubting or would be accusing my code
    I created an empty scene with nothing else but a single C# script with a single line of code in the Update()
    The same thing is happening there! OMG I am going crazy

    Here is the line you can use to test the bug : Debug.Log(UnityEngine.InputSystem.Mouse.current.delta.ReadValue());

    Simply launch the scene, have the script somewhere on a game object in the scene, just move the mouse, the values will be show in the console, just as it should
    Now if you stop moving, it will say 0,0
    But now if you start clicking buttons or scroll, here you go it is gonna spit numbers, even if the mouse is standing still, worse, it is spitting the same numbers that were used when you moved the mouse like 5 seconds ago, it's like the Vector2 never resets to 0 when the mouse is not moving! Wtf!

    Explanation please?
     
  3. valentin56610

    valentin56610

    Joined:
    Jan 22, 2019
    Posts:
    151
    @mk0a1a Thank you for trying this out!

    then it must be a platform issue, I do not have any windows pc around to test it there

    I filed a bug report already waiting for an answer from them there!

    I also saw that that’s what got me thinking into that it could be a platform specific bug since somebody on reddit tried it and didn’t notice any bug

    ehh …. Thanks again for dropping a comment!
     
  4. ashtorak

    ashtorak

    Joined:
    Feb 19, 2014
    Posts:
    53
    It's platform specific. I just noticed it too on Linux but not on Windows. Would be great if you could file a bug report and report back. So far I had good experience with them fixing such bugs.
     
  5. valentin56610

    valentin56610

    Joined:
    Jan 22, 2019
    Posts:
    151
    Alright will do
    They just answered my bug submission.
    I will update the post with the ticket when I get one!
    Thanks guys

    PS : It is both in build and editor
     
    skamalk and saskenergy like this.
  6. skamalk

    skamalk

    Joined:
    Apr 19, 2022
    Posts:
    2
    Observed issue in Linux. Windows is fine. Additionally, in my case, it seems the issue occurs when cursor lockstate is ON. Didn't go deeper to ratify this though.
     
  7. valentin56610

    valentin56610

    Joined:
    Jan 22, 2019
    Posts:
    151
    Unity support team told me they were unable to reproduce the issue .. Don't know what else to do ...

    I didn't use any lock state in my case
     
  8. mstevenson

    mstevenson

    Joined:
    Sep 24, 2009
    Posts:
    189
    I'm able to reliably reproduce this issue in Unity 2021.3.2f1 on both a M1 MacBook Pro and Intel iMac running macOS Monterey. This issue has been reported a number of times in the past couple years with test projects and repro steps so I'll avoid opening a new bug, but I've included my test script below in case its useful.

    This report from October 2019 is marked as "Fixed in 2021.2.X" so this seems to be a regression:

    https://issuetracker.unity3d.com/is...er-mouse-click-while-the-cursor-is-motionless

    I've verified that the bug is still present in InputSystem 1.4 pre-release.

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.InputSystem;
    3.  
    4. public class DeltaTest : MonoBehaviour
    5. {
    6.     private void Start()
    7.     {
    8.         Application.targetFrameRate = 6;
    9.     }
    10.    
    11.     private void Update()
    12.     {
    13.         var delta = Mouse.current.delta.ReadUnprocessedValue();
    14.         var pressed = Mouse.current.leftButton.wasPressedThisFrame;
    15.         var released = Mouse.current.leftButton.wasReleasedThisFrame;
    16.         var nonZero = delta.magnitude > 0.0001;
    17.  
    18.         var message = "";
    19.         if (nonZero) message += "<color=cyan>";
    20.         message += $"{delta.ToString("F7")}  {(pressed ? "down" : released ? "up" : "")}";
    21.         if (nonZero) message += "</color>";
    22.        
    23.         Debug.Log(message);
    24.     }
    25. }
    26.  
     
    naknuknik likes this.
  9. valentin56610

    valentin56610

    Joined:
    Jan 22, 2019
    Posts:
    151
  10. valentin56610

    valentin56610

    Joined:
    Jan 22, 2019
    Posts:
    151
    UPDATED: I just tested an upgrade to Unity 2022.3.5f1, and ... the issue is gone!
     
  11. Kahlis

    Kahlis

    Joined:
    Jan 14, 2017
    Posts:
    5
    I just searched this issue for a solution because I'm facing it in Unity 2022.3.6f1...
    Maybe a downgrade in input or editor version?
     
  12. valentin56610

    valentin56610

    Joined:
    Jan 22, 2019
    Posts:
    151
    Well RIP, I guess I will no longer update
    I'm still on 2022.3.5f1 and still no issues...