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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question Camera slows down when you select a player

Discussion in 'Scripting' started by Funtik63, Aug 20, 2023.

  1. Funtik63

    Funtik63

    Joined:
    Apr 29, 2022
    Posts:
    9
    Tell me why the camera can lag if I select a player in the inspector? If you select another object, then the camera movement becomes normal
    I'm using version 2022.3.7f1


    Code (CSharp):
    1.     private void LateUpdate()
    2.     {
    3.         float mouseX = Input.GetAxis("Mouse X") * MouseSpeed * Time.deltaTime;
    4.         float mouseY = Input.GetAxis("Mouse Y") * MouseSpeed * Time.deltaTime;
    5.  
    6.        
    7.  
    8.         xRotation -= mouseY;
    9.  
    10.         xRotation = Mathf.Clamp(xRotation, -90f, 90f);
    11.         transform.localRotation = Quaternion.Euler(xRotation, 0f, 0f);
    12.      
    13.  
    14.         playerBody.Rotate(Vector3.up * mouseX);
    15.  
    16.     }
     
  2. Yoreki

    Yoreki

    Joined:
    Apr 10, 2019
    Posts:
    2,590
    Probably unrelated to the camera and more related to spikes in frametime itself. Your frametime is spiking to 15ms sometimes. You could try to check in the profiler what happens at those spikes. However im not sure if performance issues caused by the editor are properly showing up (or even supposed to).

    What have you got on your player? Something that causes large editors that have to be loaded? Or maybe a custom editor? Does the problem persist if you hide all editors on your player object? Assuming this behavior does only happen when you click on the player and not other objects in the hierarchy, it should be something players-specific being loaded by Unity to work with the object.

    Does the problem persist after restarting? It could also be a problem with the installation, or the cache.
    Maybe you find something helpful here.
     
  3. Funtik63

    Funtik63

    Joined:
    Apr 29, 2022
    Posts:
    9
    This problem is only when I click on the player, other objects are fine
    upload_2023-8-20_16-21-16.png
    upload_2023-8-20_16-21-31.png
     
  4. wideeyenow_unity

    wideeyenow_unity

    Joined:
    Oct 7, 2020
    Posts:
    728
    The only time selecting one of my own prefabs, gave massive frame drop, was because the Inspector was trying to show and populate thousands of references within lists. As the Editor itself needs to use draw calls and "Get" functions to display it's data you set to public.

    So if that's your case, use
    [HideInInspector]
    in your code in front of whatever massive public lists you might have.
     
  5. Funtik63

    Funtik63

    Joined:
    Apr 29, 2022
    Posts:
    9
    upload_2023-8-22_0-17-42.png


    I tried all the methods and went to cut the character movement script, I removed all the components and it turned out that when Rigidbody Interpolate is turned on, the camera starts to lag.
    I also tried version 2021.3.29.f1, everything works fine on it