Search Unity

problems with input at low framerates

Discussion in 'Editor & General Support' started by ratamorph, Jan 16, 2009.

Thread Status:
Not open for further replies.
  1. ratamorph

    ratamorph

    Joined:
    Sep 2, 2007
    Posts:
    458
    I noticed that when I'm running at low fps I get delayed input responses on mouse buttons. For instance if I press the mouse button very fast to shoot a prefab it keeps shooting even after I stopped pressing the mouse button.

    This is more noticeable on webplayer builds, the input documentation states that Input.GetKeyDown returns true on the frame the user pressed the key down, but seems like a buffer of my mouse clicks is being created and processed so no click is missed.

    This is terrible for my game since I expect players to mash the mouse buttons and this results in the character being locked into the shooting state for a period of time making the game unresponsive.

    I've uploaded a web player that illustrates this issue.

    http://www.c2estudio.com/manySpheresTestWeb.html

    Just mash the left mouse button and you'll see what I mean.

    I just got a lot of spheres and very high settings on shadows to force a low fps.

    The code I use to shoot is:

    Code (csharp):
    1.  
    2. var prefabToShoot : GameObject;
    3. var forceStrenght : float;
    4.  
    5. function Update ()
    6. {
    7.    
    8.     if(Input.GetKeyDown(KeyCode.Mouse0))
    9.     {
    10.         if(!prefabToShoot.rigidbody)
    11.         {
    12.             Debug.Log("prefab needs a rigidbody");
    13.             return;
    14.         }
    15.    
    16.         var instance : GameObject = Instantiate(prefabToShoot);
    17.    
    18.         instance.rigidbody.AddForce(transform.forward * forceStrenght);
    19.  
    20.     }
    21. }
    Is there anything I can do to fix this?
     
    CheeseMunchy likes this.
  2. ratamorph

    ratamorph

    Joined:
    Sep 2, 2007
    Posts:
    458
    I'd also like to add that when running on the editor the input performs a lot better to the point that this is not an issue.
     
  3. ratamorph

    ratamorph

    Joined:
    Sep 2, 2007
    Posts:
    458
    Sorry if this is a stupid question or anything, I'm sure some of you have encountered this, how did you resolve it? I really need to find a way to fix this, first I thought it was my code, that's why I wrote the little demo but now that I know it's a general issue I'm out of ideas.

    Please help... :cry:
     
  4. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    It's possible the clicks are queued at an OS level, in which case there's not much Unity can do that I can think of, although it's interesting that it doesn't happen in the editor. Actually it looks like all input is queued: if you click a lot of times and then press the right mouse button, it won't show the context menu until all the left clicks were processed. Short of "fixing" it by not having a low frame rate, I'm not sure what the answer is.

    --Eric
     
  5. Quietus2

    Quietus2

    Joined:
    Mar 28, 2008
    Posts:
    2,058
    How about trying Input.ResetInputAxes(); on MouseUp?

    if (Input.GetButtonDown ("Fire1")) {

    // fire ball }

    if (Input.GetButtonup ("Fire1")) {

    Input.ResetInputAxes();

    }

    *Edit: Never mind, it doesn't appear to flush the queue looking at the docs.
     
  6. ratamorph

    ratamorph

    Joined:
    Sep 2, 2007
    Posts:
    458
    The clicks might be getting queued by the OS, but if that's the case I wonder what the unity editor is doing so it doesn't affect it that much, whatever that is, is what I need to do, any unity devs reading? can you give me a hint?
     
  7. ratamorph

    ratamorph

    Joined:
    Sep 2, 2007
    Posts:
    458
    Still unable to figure this one out and I'm afraid its out of my hands now, without knowing how unity handles its input and how it does it in the editor to minimize the impact on low fps.

    I seem to remember back when I learned direct input 9 that you could use buffered and unbuffered input, I'm not sure what unity uses for it's input or how they initialize it, but if I could just set that to use unbuffered input my problem would go away.

    Again without more knowledge I'm just assuming things that are out of my control... What I do need is to fix my game...

    Is this something I have to pay support for? Someone from Unity please answer, we really need to get this fixed or have more clarity on the issue.

    Thanks Eric and Quietus for their replies, atleast I know I'm not asking something trivial. :?
     
  8. ratamorph

    ratamorph

    Joined:
    Sep 2, 2007
    Posts:
    458
    After some testing with the help of some in the irc channel I found out that this issue is related only to mouse button input, if I do the same but check for the spacebar everything behaves as expected. Any clues?

    This issue happens in web player and standalones (macOSX, can't verify on windows) and it doesn't happen at all when running the scene on the editor.
     
  9. shaun

    shaun

    Joined:
    Mar 23, 2007
    Posts:
    728
    I have the same issue in our game - sometimes it gets so serious that the player keeps firing for 10 or more seconds until the buffer is fully dequeued.
    I'm sure it's something simple, and one of the Unity guys can give some input, no pun intended.
     
  10. ratamorph

    ratamorph

    Joined:
    Sep 2, 2007
    Posts:
    458
    Thank God I'm not the only one who has an issue with this! ;-)

    I mean sorry you have the same problem as me, lets hope we get some info on what is causing this and how to prevent it from happening.

    I've been actively asking in the irc and currently emailing support, I'll post any findings in here.

    By the way does the issue happen in the editor for you?
     
  11. ratamorph

    ratamorph

    Joined:
    Sep 2, 2007
    Posts:
    458
    A quick update...

    I recieved an email form UT, this issue is related to how the unity player for macosx handles the mouse input and will look into a solution on Unity 2.5 or 2.6.

    Hoping its 2.5...
     
  12. joegalaxy

    joegalaxy

    Joined:
    Nov 6, 2008
    Posts:
    16
    Hi, ratamorph,
    I have that same problem in my game, but it's related to Keypad input. Anyway it's the same problem, it looks it returns true in ALL the frames the user keep the key pressed and not only on the first frame. Your last post is rather old, did you got some news lately?
    Many thanks.
     
  13. zelk

    zelk

    Joined:
    Mar 13, 2009
    Posts:
    246
    I have this problem when reading the keyboard. I run my input reading in FixedUpdate. I don't know if that is right or not. When I have high fps, the user input is lost for ever. When I have low fps, the user input is read more than once.

    Code (csharp):
    1.  
    2.     public override void ReadUserInput()
    3.     {
    4.         if (Input.GetButtonDown("GearUp"))
    5.         {
    6.             mCurrentGearIndex++;
    7.         }
    8.  
    9.         if (Input.GetButtonDown("GearDown"))
    10.         {
    11.             mCurrentGearIndex--;
    12.         }
    13.     }
    14.  
    Anyone knows a solution for this?

    /Zelk
     
  14. modernator24

    modernator24

    Joined:
    Apr 7, 2017
    Posts:
    205
    Have the same issue here, it's quite critical in my game. Any news?
     
    CheeseMunchy likes this.
  15. modernator24

    modernator24

    Joined:
    Apr 7, 2017
    Posts:
    205
    I just tested with this code:

    Code (CSharp):
    1. void Update() {
    2.         if(Input.GetKeyDown(KeyCode.RightArrow)) {
    3.             print("Pressed " + Time.time);
    4.         }
    5. }
    In the low frame rate, I can see "Pressed" a lot. (Even not low frame rate, sometimes I can see it)
     
    CheeseMunchy likes this.
  16. modernator24

    modernator24

    Joined:
    Apr 7, 2017
    Posts:
    205
    Note that using Unity 2019.1.0f2
     
    CheeseMunchy likes this.
  17. CheeseMunchy

    CheeseMunchy

    Joined:
    Aug 11, 2019
    Posts:
    2
    Yeahh this is still an issue. Mouse inputs are lost at low framerates with update and fixedupdate on windows.. I'm wondering how people work around this. (2021.3.16f1)
     
  18. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,680
    Please do not revive 15 year old threads. Make a new one if you are having a similar sounding issue.

    You're supposed to read input in Update(). As long as you do that, no input events will be lost. Do not read input in FixedUpdate() - it can run more than one time a frame (which will cause you to read same inputs twice) or less than once per frame (which will cause you to miss inputs).
     
    MelvMay likes this.
Thread Status:
Not open for further replies.