Search Unity

  1. Unity 2020.2 has been released.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Can someone explain what is going on with unity input?

Discussion in 'Editor & General Support' started by Crystalline, May 12, 2016.

  1. Crystalline


    Sep 11, 2013

    Look at this video I recorded. Its 8x times slower and I made it to show how unity deals with input .

    As you can see, it takes quite a bit of time for Unity to notice I started moving my cursor.. Why is it so slow? I have Vsync off,mouse script is second or first in script execution order, 60 stable fps(simple scene too).
    It is really bad, bad aim accuracy for a shooter game.Any other games I play have crisp mouse response.
    Why is this? Is there anything to do?
    I ve seen this question actually been asked before by others, but nobody wants to deal with it .Seems like devs want to dodge the question/issue.

    Also, check this out.
  2. HiddenMonk


    Dec 19, 2014
    I dont know if there really is something on unity side causing the mouse to be slow, but can we see some code just in case it might be something on your side?
    For example, I used to do Input.GetAxis("Mouse X") * Time.deltaTime, but later learned you are not suppose to multiply it by deltaTime since the value Mouse X returns is the distance the mouse moved since last frame, which is already framerate independent.
    Multiplying it by deltaTime will now make it framerate dependent, which is bad.
  3. Crystalline


    Sep 11, 2013
    Code (CSharp):
    2.         if (axes == RotationAxes.MouseXAndY)
    3.         {
    4.             float rotationX = transform.localEulerAngles.y + Input.GetAxis("Mouse X") * sensitivityX;
    6.             rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
    7.             rotationY = Mathf.Clamp (rotationY, minimumY, maximumY);
    9.             transform.localEulerAngles = new Vector3(-rotationY, rotationX, 0);
    10.         }
    11.         else if (axes == RotationAxes.MouseX)
    12.         {
    13.             transform.Rotate(0, Input.GetAxis("Mouse X") * sensitivityX, 0);
    14.         }
    15.         else
    16.         {
    17.             rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
    18.             rotationY = Mathf.Clamp (rotationY, minimumY, maximumY);
    20.             transform.localEulerAngles = new Vector3(-rotationY, transform.localEulerAngles.y, 0);
    21.         }
    22.     }
    As you can see, this code does not use any timeDelta.
  4. HiddenMonk


    Dec 19, 2014
    Edit - My tests were flawed so all the results are wrong. See this thread for an update


    I was curious, so I did a test and it seems that unity does have some delay with inputs, though I dont think this is your issue.
    Its hard to tell with your video, but is your issue that your mouse feels like its being smoothed? Maybe thats just the slow motion you did that is making it look weird to me. Also, those mouse trails makes it hard to tell what is a single frame and what not.

    There was a bug about VR causing input lag. Do you have that enabled?
    Edit -> Project settings -> Player -> Other Settings and under "Rendering" make sure "Virtual Reality Supported" is unchecked.
    Source -

    Here was my input test...
    (The video says my framerate was 170, but I think it was actually around 100 due to the recording making things slower, but that shouldnt matter anyways)
    Edit - Removed video due to inaccurate test

    The mouse code was just this
    Code (CSharp):
    2. using UnityEngine;
    4. public class Mouse : MonoBehaviour
    5. {
    6.     public float speed = 10000;
    8.     void Update()
    9.     {
    10.         transform.Rotate(0, Input.GetAxis("Mouse X") * speed, 0);
    11.     }
    12. }

    It seems to be on average a 2 - 3 frames delay (never lower than 2, and actually, I might have never gotten 2, only 3). I was expecting 0 - 1 frame delay. When I tested in a non unity game, I seemed to be getting 0 - 2 frames delay, which makes me wonder what might be going on. I never seemed to get 3 frame delay in the non unity game though, mainly 2 frame delay, though maybe my tests are just faulty?

    Edit - I also did a test with 15 framerate lock, and it seems the input delay was still 3 frames, which means the lower your framerate, the more you will notice the input delay. Its as if for some reason unity needs 3 frames before updating the mouse values (and possibly all input values).

    I tried testing keyboard input by bringing up windows On Screen Keyboard, which will highlight the shift key when pressing it, however, it seems the On Screen Keyboard doesnt highlight in time consistently since in my recording unity would react to my input sometimes before or after the On Screen Keyboard highlighted.

    Now I too would like to get some input from the people at unity (no pun intended =D).

    Maybe this will soon be fixed with the new unity input system?
    It states -

    "Is it possible to poll input at higher frequency than the frame rate?
    Not yet but it's planned. It will be possible to get the input in event form and check the time-stamps of each event. Alternatively it will also be possible to just poll the input state in FixedUpdate rather than Update.

    source -

    Though, if unity is already not detecting input changes between multiple frames, would a higher frequency even matter?
    Is this bug reporting worthy?
    Last edited: Mar 21, 2017
  5. Crystalline


    Sep 11, 2013
    Very good video demonstration. It is now clear that unity input is lagging behind.
    I got no idea why the developers took no time to fix this untill now. It should ve been fairly simple, maybe?

    What I notice, is a delay when I start moving the mouse, and when I stop( obviously , its still there while continously moving it).
    The video I recorded is quite unprofessional, but you can easily see how much it takes for unity to notice and start moving the camera.The cursor is way ahead of unity camera movement.

    However,I decided to test this in Blender Game Engine, which is quite an old engine based off Blender ,and I was surprised of how much more responsive the mouse input felt.Not to mention how crisp it feels in Counter Strike or Call of Duty games.

    Hopefully this issue will be solved in the upcoming input system!
    Last edited: May 14, 2016
    HiddenMonk likes this.
  6. HiddenMonk


    Dec 19, 2014