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
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Official Experimental Dependency Viewer

Discussion in 'Editor Workflows' started by sebastienp_unity, Aug 19, 2021.

  1. Chaosed0

    Chaosed0

    Joined:
    Jun 19, 2013
    Posts:
    19
    Just want to throw in that our team is finding this tool exceptionally useful, albeit situationally. Glad to hear this is something that will still be worked on.
     
  2. erispe10

    erispe10

    Joined:
    May 16, 2022
    Posts:
    8
    I hope this becomes a core feature in Unity and not an optional plugin, so that other tools can rely on dependency checking features. Sadly the official Perforce plugin doesn't do any kind of dependency checking. With the Perforce plugin it's too easy to submit a prefab without submitting the models it's using, or materials without their textures. It should just automatically add all added/checked out files that are connected to the thing you are submitting to the changelist. So it needs to be a core part of Unity so the Perforce team can update their plugin
     
  3. Kamyker

    Kamyker

    Joined:
    May 14, 2013
    Posts:
    1,084
    +1 this makes me much more productive.

    Feedback:
    1. Few right click context actions are missing like "Properties" that opens separate inspector.
    2. Tab name should be called as the tool is, not as a name of searched object.

    3. Window shouldn't update when it's hidden (hidden as other tab is selected). In other words if I select Game tab I don't expect Dependency Viewer to do any work (and lag editor) when selecting assets.
     
    Last edited: Oct 27, 2022
  4. Kamyker

    Kamyker

    Joined:
    May 14, 2013
    Posts:
    1,084
    Bug/missing feature: selecting object in a prefab (in prefab edit mode) doesn't show any deps.
     
  5. sebastienp_unity

    sebastienp_unity

    Unity Technologies

    Joined:
    Feb 16, 2018
    Posts:
    168
    Thanks for the feedback Kamyker,

    The Dependency Manager is on the mid term roadmap, so hopefully your bugs/feedback/criticisms will be addressed.

     
  6. ODINKONG

    ODINKONG

    Joined:
    Nov 4, 2014
    Posts:
    111
    Was loving this when I opened it up for the first time and started reorganizing stuff. Then I moved a big folder and now it won't show anything. It gives this error for the first asset I click on then the whole editor runs at 3fps until I restart unity. I tried re importing assets but no luck. :/

    Code (CSharp):
    1. KeyNotFoundException: The given key '10762' was not present in the dictionary.
    2. System.Collections.Concurrent.ConcurrentDictionary`2[TKey,TValue].ThrowKeyNotFoundException (System.Object key) (at <6073cf49ed704e958b8a66d540dea948>:0)
    3. System.Collections.Concurrent.ConcurrentDictionary`2[TKey,TValue].get_Item (TKey key) (at <6073cf49ed704e958b8a66d540dea948>:0)
    4. UnityEditor.Search.SearchIndexer.BuildDocumentIndexTable () (at <55096f5f655942e589440a214deeeab9>:0)
    5. UnityEditor.Search.SearchIndexer.ApplyIndexes (System.Collections.Concurrent.ConcurrentDictionary`2[TKey,TValue] documents, UnityEditor.Search.SearchIndexEntry[] entries, System.Collections.Generic.Dictionary`2[TKey,TValue] hashes, System.Collections.Generic.Dictionary`2[TKey,TValue] metainfos) (at <55096f5f655942e589440a214deeeab9>:0)
    6. UnityEditor.Search.SearchIndexer.Read (System.IO.Stream stream, System.Boolean checkVersionOnly) (at <55096f5f655942e589440a214deeeab9>:0)
    7. UnityEditor.Search.SearchIndexer+<>c__DisplayClass65_0.<LoadBytes>b__0 () (at <55096f5f655942e589440a214deeeab9>:0)
    8. System.Threading.ThreadHelper.ThreadStart_Context (System.Object state) (at <6073cf49ed704e958b8a66d540dea948>:0)
    9. System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) (at <6073cf49ed704e958b8a66d540dea948>:0)
    10. System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) (at <6073cf49ed704e958b8a66d540dea948>:0)
    11. System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state) (at <6073cf49ed704e958b8a66d540dea948>:0)
    12. System.Threading.ThreadHelper.ThreadStart () (at <6073cf49ed704e958b8a66d540dea948>:0)
    13. UnityEngine.<>c:<RegisterUECatcher>b__0_0(Object, UnhandledExceptionEventArgs)
     
  7. sebastienp_unity

    sebastienp_unity

    Unity Technologies

    Joined:
    Feb 16, 2018
    Posts:
    168
    Hum, can you try regenerating the Asset Dependency DataBase?

    upload_2022-11-22_9-30-6.png


     
  8. ODINKONG

    ODINKONG

    Joined:
    Nov 4, 2014
    Posts:
    111
    I imported the package again after using asset hunter pro for about a week and it's working again now, so I wasn't able to check if that would fix it or not. I'll try that if it breaks again though and let you know if it works.

    Asset hunter pro can rebuild dependencies so maybe it's doing something similar in the background and that fixed it? I don't know, but I do have a feature request now.

    Little icons in the library for which assets have dependencies or are dependent. Asset hunter pro has this and it's quite useful.
     
  9. sebastienp_unity

    sebastienp_unity

    Unity Technologies

    Joined:
    Feb 16, 2018
    Posts:
    168
    Thanks for the feedback. I will notify our Product Manager to look at Asset Hunter Pro.
     
  10. OBiwer

    OBiwer

    Joined:
    Aug 2, 2022
    Posts:
    61
    I really like the dependency viewer! Just encountered quite noticable (2-3 seconds) hickups when: first removing a object reference and then select another object in the hierarchy.

    those hickups are also present if the window is not active (but present as an inactive tab)

    I looked at it with deep profiling:

    upload_2023-4-13_11-21-17.png

    maybe it helps.
     
    laurentlavigne likes this.
  11. sebastienp_unity

    sebastienp_unity

    Unity Technologies

    Joined:
    Feb 16, 2018
    Posts:
    168
    We will try to optimize the Depdency Manager when we make it a proper tool in Unity. Thanks for the feedback.

     
    Lars-Steenhoff likes this.
  12. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    5,996
    This is nice.
    Not sure black on blue is the most readable tho ;)
    upload_2023-5-11_21-13-28.png
     
  13. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    5,996
    bug: dependancy graph view doesn't show anything when dropping an instance, making is nearly as useless for in-scene work as show reference in scene.
     
    Last edited: May 16, 2023
  14. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    5,996
    bug: dependency viewer still show components referencing the selection if the reference was changed to something else.
     
  15. RandomUnityDev123

    RandomUnityDev123

    Joined:
    Oct 28, 2022
    Posts:
    11
    I started using this tool today and it's priceless. How difficult would it be to implement a button that dumps the entire index as a text/searchable file?
     
  16. sebastienp_unity

    sebastienp_unity

    Unity Technologies

    Joined:
    Feb 16, 2018
    Posts:
    168
    Hi,

    currently the Dependency Viewer is still in prototype and not being iterated on actively. I will keep note of this feature for when we reconvene working on it.

     
    Lars-Steenhoff likes this.
  17. Artemko_one

    Artemko_one

    Joined:
    Jan 3, 2018
    Posts:
    4
    Very useful feature. Unfortunatly was not able to add it to my work project, because it requires quick search package. And quick search automatically triggers a two-hour+ long indexing of the Assets folder on first open for every user, which cannot be disabled in settings for some reason and can only be disabled manually.
     
  18. fnnbrr

    fnnbrr

    Joined:
    Jan 26, 2021
    Posts:
    10
    I've been finding the search extensions repo incredibly useful; I just made this little inspector mod using it so that I get a Rider code vision-esque "usages" foldout drawn right in the header for the selected object.

    An example of the foldout opened:
    upload_2023-9-8_18-4-49.png

    Code (CSharp):
    1. using System.Collections.Generic;
    2. using UnityEditor;
    3. using UnityEditor.Search;
    4. using UnityEngine;
    5.  
    6. // TODO: REQUIRES THIS PACKAGE: https://github.com/Unity-Technologies/com.unity.search.extensions
    7. // and this script needs to be placed inside the com.unity.search.extensions.editor asmdef using an asmref,
    8. // see how here: https://docs.unity3d.com/Manual/class-AssemblyDefinitionReferenceImporter.html
    9.  
    10. // NOTE: Future work would ideally be able to index and draw headers for individual components, but that would be an
    11. // entirely different approach both for searching and for drawing headers.
    12.  
    13. /// <summary>
    14. /// Expands UnityEngine.Object headers to show a dropdown list of usages/references to the target Object.
    15. /// Inspired by the "Code Vision usages" functionality in Rider/JetBrains IDEs.
    16. /// Makes use of the new Unity Search indexing and API: https://docs.unity3d.com/Manual/search-overview.html
    17. /// </summary>
    18. [InitializeOnLoadAttribute]
    19. static class ObjectUsagesHeader
    20. {
    21.     // TODO: Limit the size of this cache. Right now it gets cleared on domain reload which is often enough for me.
    22.     private static readonly Dictionary<Editor, Object[]> UsagesCache = new();
    23.  
    24.     private static bool _expandDropdown = false;
    25.  
    26.     // Copied from UnityEditor.Search.Dependency.FindUsages()
    27.     private static readonly string[] SearchProviderIds = { "dep", "scene", "asset", "adb" };
    28.  
    29.     static ObjectUsagesHeader()
    30.     {
    31.         Editor.finishedDefaultHeaderGUI -= AppendUsagesHeader;
    32.         Editor.finishedDefaultHeaderGUI += AppendUsagesHeader;
    33.     }
    34.  
    35.     private static void AppendUsagesHeader(Editor editor)
    36.     {
    37.         EditorGUILayout.BeginVertical(new GUIStyle() { padding = new RectOffset(20, 5, 0, 0) });
    38.      
    39.         if (UsagesCache.TryGetValue(editor, out Object[] usages))
    40.         {
    41.             if (usages != null)  // Cache hit, search has completed and results are ready to query
    42.             {
    43.                 DrawUsages(usages);
    44.             }
    45.             else  // Cache hit, but search is still in progress
    46.             {
    47.                 EditorGUILayout.LabelField("Finding usages...");
    48.             }
    49.         }
    50.         else  // Cache miss, start search
    51.         {
    52.             UsagesCache[editor] = null;
    53.          
    54.             StartSearch(editor);
    55.          
    56.             EditorGUILayout.LabelField("Finding usages...");
    57.          
    58.             _expandDropdown = false;  // Hacky af but gets the intended behavior ;)
    59.         }
    60.      
    61.         EditorGUILayout.EndVertical();
    62.     }
    63.  
    64.     private static void DrawUsages(Object[] usages)
    65.     {
    66.         string foldoutLabel = usages.Length == 1 ? "1 usage" : $"{usages.Length} usages";
    67.      
    68.         _expandDropdown = EditorGUILayout.BeginFoldoutHeaderGroup(_expandDropdown, foldoutLabel, null, ShowContextMenu);
    69.      
    70.         if (_expandDropdown)
    71.         {
    72.             using (new EditorGUI.DisabledScope(true))  // Disable assigning anything to these ObjectFields
    73.             {
    74.                 foreach (Object usage in usages)
    75.                 {
    76.                     EditorGUILayout.ObjectField(usage, usage.GetType(), true);
    77.                 }
    78.             }
    79.         }
    80.      
    81.         EditorGUILayout.EndFoldoutHeaderGroup();
    82.     }
    83.  
    84.     private static void ShowContextMenu(Rect position)
    85.     {
    86.         GenericMenu menu = new();
    87.      
    88.         if (!Dependency.HasIndex())
    89.         {
    90.             menu.AddItem(new GUIContent("Build Dependency Index"), false, Dependency.Build);
    91.         }
    92.         else if (Dependency.HasUpdate() && Dependency.IsReady())
    93.         {
    94.             menu.AddItem(new GUIContent("Update Dependency Index"), false, () => Dependency.Update(null));
    95.         }
    96.         else
    97.         {
    98.             menu.AddDisabledItem(new GUIContent("Update Dependency Index"));
    99.         }
    100.      
    101.         menu.DropDown(position);
    102.     }
    103.  
    104.     private static void StartSearch(Editor editor)
    105.     {
    106.         string path = UnityEditor.Search.SearchUtils.GetObjectPath(editor.target);
    107.      
    108.         SearchContext searchContext = SearchService.CreateContext(SearchProviderIds, $"ref=\"{path}\"");
    109.      
    110.         SearchService.Request(searchContext, (_, list) => OnSearchCompleted(editor, list));
    111.     }
    112.  
    113.     private static void OnSearchCompleted(Editor editor, IList<SearchItem> searchItems)
    114.     {
    115.         Object[] usages = new Object[searchItems.Count];
    116.      
    117.         for (int i = 0; i < searchItems.Count; i++)
    118.         {
    119.             usages[i] = searchItems[i].ToObject();
    120.         }
    121.      
    122.         UsagesCache[editor] = usages;
    123.     }
    124. }
     
  19. lochrist

    lochrist

    Joined:
    Sep 29, 2017
    Posts:
    2
    Hi @Artemko_one

    Sorry for the long delay.

    Which version of unity are you using? the QuickSearch package is only for 20.3. The Search workflow is available as a core feature since 21.1.

    The Dependency Viewer is built on top of the Search workflow backend. We scan all assets in your project and establish a dependency map. Dependending on the size of the project it can be long. By default if your project DOESN'T contain an index settings file (more on this below) we create one such file in your UserSettings folder and start indexing. Indexing of assets is done in the AssetWorker background process (so NOT on the main editor process and it shouldn't generally slow down your unity experience).

    By default we will try to index every assets and folders of your project. If you want to limit the amount of stuff being indexed you can create your own index settings file using the Index Manager (Main menu Window -> search -> Index Manager). This could allow you to specify which folders you want to not be indexed or to limit the size of the indexation. Also, if your Index settings file is saved in your project, any users will have the same indexing settings.

    When Indexation is done, we will only do incremental update according to assets changes.

    If your studio uses the Asset Server and you have a main machine doing project importation AND indexing, all indexing artifacts should be available through the Asset Server. Which means indexation should be way quicker for clients of the Asset Server.

    I hope this helps clarifies the search workflow.

    Thanks for your feedback,

    Sebastien

     
  20. sebastienp_unity

    sebastienp_unity

    Unity Technologies

    Joined:
    Feb 16, 2018
    Posts:
    168
    Apologies I posted my last reply from my personal account. Here is the same post but from my Unity Employee account:

    Hi @Artemko_one

    Sorry for the long delay.

    Which version of unity are you using? the QuickSearch package is only for 20.3. The Search workflow is available as a core feature since 21.1.

    The Dependency Viewer is built on top of the Search workflow backend. We scan all assets in your project and establish a dependency map. Dependending on the size of the project it can be long. By default if your project DOESN'T contain an index settings file (more on this below) we create one such file in your UserSettings folder and start indexing. Indexing of assets is done in the AssetWorker background process (so NOT on the main editor process and it shouldn't generally slow down your unity experience).

    By default we will try to index every assets and folders of your project. If you want to limit the amount of stuff being indexed you can create your own index settings file using the Index Manager (Main menu Window -> search -> Index Manager). This could allow you to specify which folders you want to not be indexed or to limit the size of the indexation. Also, if your Index settings file is saved in your project, any users will have the same indexing settings.

    When Indexation is done, we will only do incremental update according to assets changes.

    If your studio uses the Asset Server and you have a main machine doing project importation AND indexing, all indexing artifacts should be available through the Asset Server. Which means indexation should be way quicker for clients of the Asset Server.

    I hope this helps clarifies the search workflow.

    Thanks for your feedback,

    Sebastien

     
  21. sebastienp_unity

    sebastienp_unity

    Unity Technologies

    Joined:
    Feb 16, 2018
    Posts:
    168
    Good job @fnnbrr ,

    Thanks for your contribution.

    Seb

     
  22. Artemko_one

    Artemko_one

    Joined:
    Jan 3, 2018
    Posts:
    4
    Hi,

    We are using 2020.3.48 version. There is no problem with indexing of Dependency Viewer package. Indexing of folders that i need is taking a few minutes only. The problem i want to share comes from the QuickSearch package which is required.

    I've been looking into this package more than a mount ago, but i hope i remember everything correctly:

    QuickSearch by default is indexing the whole Assets folder. Which takes too much time and RAM (2+ hours and many gigabytes of RAM on top of up to 14gb that our project could eat while in playmode, essentially blocking work processes).
    Yes i can stop that default indexing, go to settings and change folders that i want to index by QuickSearch. But that would be only for me. And those settings are stored in the EditorPrefs (windows registry), which is outside of the project folder and therefore can't be pulled from VCS to others. I didn't find there an option to save those index settings as a file and track that selection in version control.
    Did i missed something? If so, could you please tell where those settings are?

    The reason i don't want QuickSearch be imported in our project is that we would need to tell every person working on a project what it is and that they need to stop that default indexing process.

    Didn't think about using an Asset Server. Will look into it, thanks!
     
  23. Artemko_one

    Artemko_one

    Joined:
    Jan 3, 2018
    Posts:
    4
    Well what i missed is that QuickSearch indexing of Assets folder does not start if you select the "minimal" indexing option in the window that appears after installing the package. That solves my issue!
     
  24. sebastienp_unity

    sebastienp_unity

    Unity Technologies

    Joined:
    Feb 16, 2018
    Posts:
    168
    Hi @Artemko_one ,

    By default if your project does not contain an Index, we create the Index settings file in your <Project>\UserSettings folder. Which means the index serttings are per user.

    That said, you can chose to create an Index using the Index Manager in your Project (generally at the root of the Assets folder). This index and its settings would then be shared among all of your co-workers thus ensuring a common search experience.

    We are working on ensuring no Asset indexing would happen during playmode.

    I hope this helps. and Thanks for your feedback.

    Seb