Search Unity

Resolved Gizmo freezing Editor

Discussion in 'Editor & General Support' started by FrankvHoof, Feb 5, 2021.

  1. FrankvHoof

    FrankvHoof

    Joined:
    Nov 3, 2014
    Posts:
    233
    For some reason one of my Gizmos is 'freezing' the editor.
    With the gizmo enabled the framerate drops so much that the entire editor freezes and a loading-window (Hold on (busy for x)...) is displayed with "GizmoManager.DrawGizmos" as the Task.

    In my opinion this Gizmo should not be this 'heavy'. All it is doing is drawing a Quad.
    The 'quadMesh'-variable is static, so it should only load once for all instances.
    There are also only 25 instances of this Object in the scene. The Gizmos render fine when NOT in Play-Mode.

    Code (CSharp):
    1.  
    2. /// <summary>
    3. /// Draws Gizmo for this Plane
    4. /// </summary>
    5. private void OnDrawGizmosSelected()
    6. {
    7.     if (quadMesh == null)
    8.     {
    9. #if UNITY_EDITOR
    10.         quadMesh = AssetDatabase.LoadAssetAtPath<Mesh>(MARConstants.Models.QuadMesh);
    11.         quadMesh.RecalculateNormals(); // Normals aren't parsed when loading from path
    12. #endif
    13.     }
    14.     if (quadMesh != null)
    15.     {
    16.         Gizmos.color = gizmoColor;
    17.         // Normal for plane should be UP. Mesh has it as Forward
    18.         Quaternion rotation = transform.rotation * Quaternion.AngleAxis(-90f, Vector3.right);
    19.         Gizmos.DrawMesh(quadMesh, -1, transform.position, rotation, new Vector3(Size.x, Size.y, 1f));
    20.     }
    21.     else LoggingLevel.Debug.Log("Couldn't find Mesh for Gizmo. Are you not in the Editor?");
    22. }
    23.  
    Is Gizmos.DrawMesh just such a huge resource-drain?
    If so, is there another way that I can render a Gizmo-Plane?
     
  2. FrankvHoof

    FrankvHoof

    Joined:
    Nov 3, 2014
    Posts:
    233
    After Profiling, the performance-drain seems to be coming completely from Gizmos.DrawMesh:



    If the Scene-Camera is static and not moving, this spike happens once every few tens of frames.
    If the Scene-Camera moves, it appears to be happening every (other?) frame.
     
  3. FrankvHoof

    FrankvHoof

    Joined:
    Nov 3, 2014
    Posts:
    233
    Resolved.

    Turns out it wasn't Graphics.DrawMesh.
    In the call to Graphics.DrawMesh, I'm referencing Size.x and Size.y.
    Due to a forgotten 'transform.hasChanged = false', this was causing the underlying object to re-calculate its collider every frame (which runs a job transposing all vertices from local- to worldspace).
     
unityunity