Search Unity

LODGroup inspector slows editor

Discussion in 'Editor & General Support' started by OndrejP, Sep 2, 2020.

  1. OndrejP

    OndrejP

    Joined:
    Jul 19, 2017
    Posts:
    304
    When LODGroup is visible in inspector (even collapsed) and scene camera is moving, all inspectors are being constantly repainted. This causes issues with features like SHIFT+F (lock camera onto moving object).

    It becomes really big issue, when there's many components on the game object, because ALL are repainted every frame.

    Simple repro steps:
    1) Create empty game object
    2) Add 30 components (e.g. BoxColliders, AudioSources)
    3) Open profiler, select editor profiling and start profiling
    4) Rotate scene view - performance is good
    5) Add LODGroup (no need to setup LODs or anything)
    6) Rotate scene view - performance is terrible

    Problematic code:
    Code (CSharp):
    1. // UnityEditor.LODGroupEditor
    2. public void Update()
    3. {
    4.     if (!(SceneView.lastActiveSceneView == null) && !(SceneView.lastActiveSceneView.camera == null) && SceneView.lastActiveSceneView.camera.transform.position != m_LastCameraPos)
    5.     {
    6.         m_LastCameraPos = SceneView.lastActiveSceneView.camera.transform.position;
    7.         Repaint();
    8.     }
    9. }
    10.  
    My opinion is that this code is here to update LOD "slider" when scene view camera position changes.

    How to fix it:
    1) When component is collapsed, don't call Repaint
    - LOD slider is not visible anyways
    - simple modification of code above to detect whether component is collapsed

    2) Don't detect position change, detect distance change
    - since LOD slider depends only on distance, detecting distance from camera makes sense
    - add threshold and repaint inspectors only when change is bigger than lets say 1-2%
    - this would completely fix the issue for SHIFT+F lock mode and camera rotation

    3) Call repaint with lower frequency
    - not ideal - stuttering, but still better than constantly slow performance
    - additionally fixes the issue for cases like zooming, panning...

    upload_2020-9-2_12-36-13.png
     
  2. silentslack

    silentslack

    Joined:
    Apr 5, 2013
    Posts:
    393
    Yep, seeing this also
     
  3. OndrejP

    OndrejP

    Joined:
    Jul 19, 2017
    Posts:
    304
    The issue is still there and I can confirm that my guess above is correct.

    Unity team, please fix this issue.
    Simple check for component being expanded would solve the issue for 95% of use cases.