Search Unity

  1. We are migrating the Unity Forums to Unity Discussions by the end of July. Read our announcement for more information and let us know if you have any questions.
    Dismiss Notice
  2. Dismiss Notice

Question Why search in hirerachy could work very very slow.

Discussion in 'Editor & General Support' started by nikolay_i, Aug 3, 2020.

  1. nikolay_i

    nikolay_i

    Joined:
    Jan 5, 2020
    Posts:
    13
    1. we have 20332 components and 16723 gameObjects, on the scene (used following script)
      Code (CSharp):
      1. public class ObjectCounter : MonoBehaviour
      2. {
      3.     [MenuItem("Window/CountObjects")]
      4.     private static void Count()
      5.     {
      6.         var components = FindObjectsOfType<MonoBehaviour>();
      7.  
      8.         HashSet<GameObject> go = new HashSet<GameObject>();
      9.         components.ForEach((component) =>
      10.         {
      11.             if (!go.Contains(component.gameObject))
      12.             {
      13.                 go.Add(component.gameObject);
      14.             }
      15.         });
      16.  
      17.         Debug.Log($"components: {components.Length}, gameObjects: {go.Count}");
      18.     }
      19. }
    2. If i try to use "Find References in the scene" from Project window - it take about 15-30 minutes to complete this lookup. As I understand, when you try to search, unity editor create search request and populate it to the Hierarchy search box with following string
      ref:AssetsPrefabs/Audio/Audio.prefab
    3. If I try to manually enter the search request on the hierarchy search box manually it still take 30 minutes for unity editor. And all this time the unity editor is stuck
    4. If I create empty scene and then use the same "find references" or use manual search box - it return result immediately.
    5. It works the same slow for any kind of assets (prefabs, materials, scripts)
    6. the manual search (custom editor call) works fast, e.g. the precedure below - take less than second to execute
      Code (csharp):
      1.  
      2. var componentsToInspect = SceneManager
      3.     .GetActiveScene()
      4.     .GetRootGameObjects()
      5.     .SelectMany(gameObject => gameObject.GetComponentsInChildren<Component>(true))
      6.     .ToArray();
      7.  
    all of this with Unity 2019.2.21f1, PC specs: SSD harddrive, Intel i7-9700K (3.60GHz), 48GB memory, RTX 2070.

    Is there any way to debug this problem or some check list to optimize the scene structure?
    Thanks.
     
    Last edited: Aug 3, 2020