Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Lagging interface

Discussion in 'Scripting' started by Johan_Valectric, Apr 26, 2020.

  1. Johan_Valectric

    Johan_Valectric

    Joined:
    Nov 28, 2019
    Posts:
    13
    Hi!
    I have run in to the strangest thing. I have downalded https://assetstore.unity.com/packages/tools/camera/free-fly-camera-140739 and one just pressing one controll at the tiem it worked fine. But now when I'm startign to get to a more done state I tried to circel around and the input gets bufferd to up to 2 seconds or more. If i don't move with wasd there is no lagg. If I change the repeat speed for the keaybord in windows it gets better but far from good.

    I have re installed twice both unity and visual studio.

    I have boiled down to this code:
    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. [RequireComponent(typeof(Camera))]
    4. public class FreeFlyCamera3 : MonoBehaviour
    5. {
    6.  
    7.     private float _movementSpeed = 0.1f;
    8.     private float _mouseSense = 1.8f;
    9.  
    10.  
    11.     private void Update()
    12.     {
    13.         // Movement
    14.         Vector3 deltaPosition = Vector3.zero;
    15.  
    16.         deltaPosition += transform.right * Input.GetAxis("Horizontal");
    17.         deltaPosition += transform.forward * Input.GetAxis("Vertical");
    18.  
    19.  
    20.         transform.position += deltaPosition * _movementSpeed * Time.deltaTime;
    21.  
    22.         // Rotation
    23.         transform.rotation *= Quaternion.AngleAxis(
    24.                         -Input.GetAxis("Mouse Y") * _mouseSense,
    25.                         Vector3.right
    26.                     );
    27.  
    28.         // Paw
    29.         transform.rotation = Quaternion.Euler(
    30.             transform.eulerAngles.x,
    31.             transform.eulerAngles.y + Input.GetAxis("Mouse X") * _mouseSense,
    32.             transform.eulerAngles.z
    33.         );
    34.  
    35.         }
    36. }
     
  2. Yoreki

    Yoreki

    Joined:
    Apr 10, 2019
    Posts:
    2,605
    I dont think the code you posted is responsible for any slowdown you are experiencing.
    Did you try profiling the actual problem? Or how dod you boil it down to this script?
     
  3. Johan_Valectric

    Johan_Valectric

    Joined:
    Nov 28, 2019
    Posts:
    13
    Thank you greatly for any input. I have tried two computers and 3 mouses and same problem when I just dropp in the code in a new scene. The proflier indecattes every thing goes fine. The profiler shows steady 1000 FPS so I can't belive my eyes.
     
  4. Yoreki

    Yoreki

    Joined:
    Apr 10, 2019
    Posts:
    2,605
    When you say 'profiler', are you actually talking about the profiling tool, or just the stats overlay which shows frametimes? FPS is an average, so if you had more than 1000 FPS and sometimes a spike in frametime, it may show 1000 FPS but still feel jittery. The profiler on the other hand is a much more powerful tool which shows you spikes in frametimes and what causes them. If the profiler does not show any spikes.. then i'm honestly not sure how there could be any jitter.
     
  5. Johan_Valectric

    Johan_Valectric

    Joined:
    Nov 28, 2019
    Posts:
    13
    I use the profiler under Windows Analysis. I have been using Unity every now and then for the last 7 years and never sene any thing like this until yeasterday. I'm baffled... The behaviour is that I move teh mouse and then stopp but the screans continiue to move for 2-4 seconds more. I have the latest graphics cards drivet and a Geforce GTX 660 so not the latest but should work.
     
  6. Johan_Valectric

    Johan_Valectric

    Joined:
    Nov 28, 2019
    Posts:
    13
    Hi!
    Some more info. This seams to be related to the latest release as I did create a new project with a older version and that works just fine. No delay at all.
     
  7. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,431
    Input.GetAxis("Horizontal") is getting a value from 0 to +/-1 and has a configurable ramp up and ramp down, like an inertia. Go to your input settings and change the gravity (that's the name of it iirc) for these Axises.
     
  8. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,431
    The new input system might be related to this changing in newly created projects.
     
  9. Johan_Valectric

    Johan_Valectric

    Joined:
    Nov 28, 2019
    Posts:
    13
    When was it roled out? I have been trying 2019.3.0f6 at first I thought it was gone but now it seams to be back. Will try to revert to 2019.1.0. This is a tech demo for a customer so It's kind of enying as this might be my shot of getting them to start with VR/AR.
     
  10. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,431
  11. Johan_Valectric

    Johan_Valectric

    Joined:
    Nov 28, 2019
    Posts:
    13
    But how can that be for a new project? Is the input settings stored inbetwen projects as defaults? Even after uninstalling and reinstaling on a other computer i see this. I'm so baffeld.
     
  12. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,431
    I have no idea and no, the default input settings for a new project come with the Unity version you created it with.
     
  13. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,431
    But unless you check these settings, we won't even know if that is actually your problem. So far, this is just my best guess from what you are describing. Just find the Axes you're using in there and play with the gravity value. If that fixes it, it fixes it. Why it changed to begin with is beyond me. If it doesn't fix it, the issue is elsewhere.
     
  14. Johan_Valectric

    Johan_Valectric

    Joined:
    Nov 28, 2019
    Posts:
    13
    I have tried some more and moste of teh time it's gone. It's not the gravity settings i guess. I have it set to 3 and it only ocures when i use wasd or other keyes. It's releated to the repeatspeed in windows. If i spin around the view in a smal circel infront of me it's continiueing after i stop up to 3 loops. It's very strange.