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. Join us on Dec 8, 2022, between 7 am & 7 pm EST, in the DOTS Dev Blitz Day 2022 - Q&A forum, Discord, and Unity3D Subreddit to learn more about DOTS directly from the Unity Developers.
    Dismiss Notice
  3. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice

Official Quick Search Preview

Discussion in 'Editor Workflows' started by benoitd_unity, Feb 26, 2019.

  1. jonathans42

    jonathans42

    Unity Technologies

    Joined:
    Jan 25, 2018
    Posts:
    514
    Ok that is indeed not good. If you open the Search Index Manager can you tell your index reports 0 bytes size? Do you know if you opened your project with an older version of Unity then later with a newer version of Unity?

    I will look at case 1417609.
    Thanks for reporting.
     
  2. MechaWolf99

    MechaWolf99

    Joined:
    Aug 22, 2017
    Posts:
    236
    Yeah, it reports 0 bytes (never loaded the index, but that would be expected I guess).
    Yeah I have updated the unity version of the project before. Only ever patch versions though (from like 2020.3.13 to 2020.3.26).


    And would you like reports of an asset(s) index not updating even if it can't be reproduced? Or would that not contain any helpful info if there is no repro?
     
  3. jonathans42

    jonathans42

    Unity Technologies

    Joined:
    Jan 25, 2018
    Posts:
    514
    If you press Build does it work afterward or it stays at 0 bytes?
     
  4. MechaWolf99

    MechaWolf99

    Joined:
    Aug 22, 2017
    Posts:
    236
    It works just fine afterward, it properly indexes everything. When I opened the index manager just now to reindex it, the elements said 0 as well as the bytes in case that helps you at all (instead of say 6507 elements like it did previously).
     
  5. jonathans42

    jonathans42

    Unity Technologies

    Joined:
    Jan 25, 2018
    Posts:
    514
    Ok if it is getting back to 0, it means something is updating the index, but it fails to do so in the process and it doesn't recover from it. If you could figure out what steps leads an index having size 0 bytes that would help a lot to repro the issue locally.
     
  6. MechaWolf99

    MechaWolf99

    Joined:
    Aug 22, 2017
    Posts:
    236
    Sure, I will try to keep an eye on it and try to keep track of what I do in case it happens again, but I wouldn't hold my breath.
     
  7. jonathans42

    jonathans42

    Unity Technologies

    Joined:
    Jan 25, 2018
    Posts:
    514
    Ok thanks.

    In all case, you can always refresh/rebuild the index using the index manager (in most cases it should do a quick recombine of search index artifacts).

    I'll try to add some more resilient code to detect that state and do an automatic refresh/recombine of the index. Maybe there is an issue with the index version bits when changing Unity versions.
     
    Lars-Steenhoff and MechaWolf99 like this.
  8. jonathans42

    jonathans42

    Unity Technologies

    Joined:
    Jan 25, 2018
    Posts:
    514
    I found one of the reason when this issue happens. I was able to repro when deleting many files at once. I have a fix for that concurrent issue, but meanwhile, let me know if it seems to match with your repro steps.

    Can you tell me which version you are on? I will prepare a fix for 22.2 and backport it up to 21.2 but it might take a while for that fix to land up to 21.2.
     
  9. MechaWolf99

    MechaWolf99

    Joined:
    Aug 22, 2017
    Posts:
    236
    Oh nice find! Unfortunately I hadn't deleted almost any assets, so it probably wasn't that for me.
    I'm on 2020.3 using the QuickSearch 3.0.28 package, so... might not be getting it haha?
     
  10. jonathans42

    jonathans42

    Unity Technologies

    Joined:
    Jan 25, 2018
    Posts:
    514
    Actually the quicksearch 3.0 package code is synced with latest 22.2 code.

    I'll submit a new 3.0.0 package revision so you'll be able to see if the issue still reproduces.
     
    MostHated and MechaWolf99 like this.
  11. MostHated

    MostHated

    Joined:
    Nov 29, 2015
    Posts:
    1,176
    I, too, am using 2020.3 (and will be until the Entities package updates to include 2021.x support) and have experienced similar symptoms on the Linux editor. I could not really pinpoint anything specific that would cause this issue, but I do recall running into this issue after having created and removed relatively large batches of assets on disk at a time.

    At the same time, I want to say that I have also noticed this after having rebuilt the index, saved my scene, etc, refreshed the editor, and closed it. Only to experience the missing size once again after having simply reopened the editor. I cannot recall if I did much else in between that though. I will try and keep an eye on it and see if I can come across anything else that might be contributing to it on my end.

    I tend to experience a number of odd things within the Linux editor, though, so it's hard to say if some issues I experience are actual issues with a package/asset, or are caused by Linux editor gremlins.
     
  12. jonathans42

    jonathans42

    Unity Technologies

    Joined:
    Jan 25, 2018
    Posts:
    514
    Hi, I just published com.unity.quicksearch@3.0.0-preview.24 if you have some time to test it and let me know if it fixes that constant re-indexing issue.

    Thanks,
     
    MostHated likes this.
  13. Yoraiz0r

    Yoraiz0r

    Joined:
    Apr 26, 2015
    Posts:
    21
    Hello,

    I've been trying out the new Unity Search feature, having read about it in the 2021.2 update's blog post.

    I'm noticing some issues I'd like to report. I've first noticed them in the 2021.2 release. I then tried updating my project to 2021.3's LTS, and they remained. I hopped on 2022.2.0a10.1539 for good measure after the fact, and they're still there.

    The gif included here uses 2022.2.0a10.1539.
    https://i.imgur.com/buizXKD.gif

    First, the only step I've taken prior to trying the search feature out, is opening the index manager and pressing save (using the default options).

    1. If the search inspector window on the right is open, then, whenever I select any item in the search, I get a warning. This warning shows up in all 3 aforementioned unity versions I've tried. It is
    Code (CSharp):
    1. UnityEditor.Search.SearchServiceItem must be instantiated using the ScriptableObject.CreateInstance method instead of new SearchServiceItem.
    2. UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)
    2. Adjusting a scriptable object's properties, from any inspector windows (be it the search window's , or the regular Unity Inspector tab) , does not reflect the change in the search window. This seems to only be reflected once I manually hit ctrl+s to save the project state. I assume the reason is that the search window only cares about asset contents, and not their transient state? can that be adjusted in any way so I can clearly witness what is the current state of my project without spamming ctrl+s?

    3. Even after hitting save, it takes a moment for the search to update the displayed values, and it does not give some feedback when it did so. Additionally, the 'Search Service Item' showing on the search window's inspector's values stay outdated until the item is re-selected.

    That's it for the issues I've witnessed so far that I can call 'bugs', though I do have another...
    4. How can I filter and select at the same time? Using the example above "select{t:CropType, name, #DaysToGrow}" , I'd like to filter this 'select' search to show only crops that take more than 3 days to grow. trying to include `>3` in the DaysToGrow section didn't seem to work, and neither did including it before the first comma of said search. I'd appreciate some clarification here, as trying to figure it from the documentation didn't yield success, please.

    Queries aside, I'm really rooting for the Search feature! I think it has amazing potential in reducing spent development time finding things, as long as it is easier to use.

    Edit: I've messed with search queries more, and from what I can understand, it seems queries for properties of scriptable objects, straight up don't work. A simple query of "t:type #fieldname>someNumber" seems to work for 3 different cases of monobehaviours, but none of scriptable objects. Is this intended?
     
    Last edited: Apr 23, 2022
    saskenergy likes this.
  14. jonathans42

    jonathans42

    Unity Technologies

    Joined:
    Jan 25, 2018
    Posts:
    514
    Hi, I will try to repro that issue and provide a fix for it.

    It is possible that some properties only get invalidated when the container asset gets saved on disk. I'll see if I can improve this.

    You can try something like this:

    select{h: t:CropType #m_DaysToGrow>3, name, #DaysToGrow}


    We also have a
    where{}
    statement you can check out for this: https://github.com/Unity-Technologies/com.unity.search.extensions/wiki/Search-Expressions#where

    Thanks a lot for the great feedback. I will try to address the issue you've raised as soon as possible. We also have a backport with many fixes that should land in 21.3 in the following weeks.
     
    JoNax97 and Yoraiz0r like this.
  15. Yoraiz0r

    Yoraiz0r

    Joined:
    Apr 26, 2015
    Posts:
    21
    I've given it a shot but as I mentioned in my edit, it seems to straight up not work as far as scriptableobjects are concerned.
    Specifically... trying to query the project, instead of the hierarchy.
    (I've removed the h: tag because I'm not looking within the scene, but the queries for DaysToGrow>3 straight up eliminate all results, even though displaying DaysToGrow clearly shows number above 3)

    I've also tried using Where, and while I can confirm it works as intended with monobehaviour searching, it does not work at all with scriptableobject searching (though , again, might be related to the numeric query itself not working?)

    Good luck! Have a fantastic week!
     
  16. jonathans42

    jonathans42

    Unity Technologies

    Joined:
    Jan 25, 2018
    Posts:
    514
    Do you mind sending me (in private) a sample project with that setup so I can see what is going on?

    Thanks,
     
    Yoraiz0r likes this.
  17. jonathans42

    jonathans42

    Unity Technologies

    Joined:
    Jan 25, 2018
    Posts:
    514
    Here's a few clarifications around the usage of
    #
    and
    @
    in a search expression:

    select{t:MySO, name, @#DaysToGrow}

    upload_2022-4-26_16-12-9.png
    All good. Here you are selecting from
    t:MySO
    the dynamic property
    #DaysToGrow
    . So a dynamic property can change in memory so you need to use the
    #
    . Not that for each selector, if non-ambiguous, you can omit the
    @
    , but otherwise it needs to be put explicitly. So I recommand you always put the
    @
    for a search expression selector.

    select{t:MySO DaysToGrow>3, name, #DaysToGrow}

    upload_2022-4-26_16-12-29.png
    In
    t:MySO DaysToGrow>3
    you are running on query on the asset provider which use indexed content. Therefore indexed content is not dynamic, so you do not need to put the #. You can find all indexed keywords in the Index Manager.
    upload_2022-4-26_16-12-50.png

    In a
    where{}
    statement, such as
    select{where{t:MySO, @#DaysToGrow>3}, name, #DaysToGrow}
    , you need to explictly state selectors using
    @
    .
    upload_2022-4-26_16-13-11.png

    Sorry for the confusion around
    #
    (for dynamic properties, i.e. in a selector or in the scene search provider) and
    @
    (the explicit selector argument marker).

    So in the end, I would recommend always using
    @
    when you are typing a selector in a
    where{}
    or
    select{}
    statement for example.

    I hope this clears it out a bit.
     
    Yoraiz0r likes this.
  18. jonathans42

    jonathans42

    Unity Technologies

    Joined:
    Jan 25, 2018
    Posts:
    514
    Also note that you do not always have to write a select{} statement to use the table view. You can simply write a normal query and add each column manually:

    upload_2022-4-26_16-23-4.png

    upload_2022-4-26_16-23-13.png

    upload_2022-4-26_16-23-39.png

    upload_2022-4-26_16-24-40.png

    You right click on a column header to edit the search column properties. Then once you are satisfied with your table view setup, you can save the query as a user or project query and re-use it later.
     
    Yoraiz0r likes this.
  19. CDF

    CDF

    Joined:
    Sep 14, 2013
    Posts:
    1,205
    Hey, I'm getting some pretty bad editor performance when using the search extensions package:
    https://github.com/Unity-Technologies/com.unity.search.extensions 1.0.1

    After searching an object by usages (Find Used By)
    The editor starts lagging quite a bit, from the profiler, it's running at 15fps

    search_profiler.png

    This is happening with/without the search window open

    If I reload scripts, the editor returns to normal.
    Is there perhaps an event not being cleaned up/registering multiple times?

    Using Unity 2021.3.0
     
    Last edited: May 2, 2022
  20. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    1,874
    This is a bug that was reported here as well, is fixed on 2022.2 and getting backported.
     
    jonathans42 and CDF like this.
  21. CDF

    CDF

    Joined:
    Sep 14, 2013
    Posts:
    1,205
    Ok great. I'll keep a look out for the update
     
    jonathans42 and MartinTilo like this.
  22. jonathans42

    jonathans42

    Unity Technologies

    Joined:
    Jan 25, 2018
    Posts:
    514
    Indeed, like @MartinTilo mentioned this stalling issue was fixed and the backport should land in 21.3 anytime soon. Let us know if it solved the issue for you? Meanwhile the workaround for now would be to open the Index Manager and rebuild the indexes, when this occurs.
     
    Last edited: May 3, 2022
  23. profanicus

    profanicus

    Joined:
    Nov 23, 2009
    Posts:
    292
    Hey there, I'm using the LTS 2021.3 version and have a bit of an issue.

    When using table view with the experimental serialized property column format, anything that directly follows a Header attribute does not display correctly. The header text displays instead, and the fields become unselectable.

    For example:
    [Header("This is a Header")]
    [SerializeField] private TestEnum testEnum;


    Default column format:
    upload_2022-5-14_10-21-23.png

    Experimental serialized column format:
    upload_2022-5-14_10-23-38.png

    It works after moving the enum away from the Header attribute:
    upload_2022-5-14_10-25-38.png
     
  24. sebastiengrenier

    sebastiengrenier

    Unity Technologies

    Joined:
    Jun 11, 2019
    Posts:
    72
    Hi @profanicus, can you log a bug and share the case number? Thank you!
     
  25. profanicus

    profanicus

    Joined:
    Nov 23, 2009
    Posts:
    292
    Sure, case number is 1428547 :)
     
  26. nehvaleem

    nehvaleem

    Joined:
    Dec 13, 2012
    Posts:
    249
    Hi, I didn't find a dedicated forum for Unity Search, so I guess this thread will fit my question best. I would like to ask what is the preferred way of searching all the prefabs with the component that derives from BaseClass? Unfortunately typing only t:BaseClass yields no results. My case is that the subclasses don't necessarily have the "BaseClass" in their names so it isn't possible to check against their filename/type only.
     
  27. sebastiengrenier

    sebastiengrenier

    Unity Technologies

    Joined:
    Jun 11, 2019
    Posts:
    72
    Hi.
    This is not supported at the moment. We currently only index the type of the component, but not the hierarchy of types. This is something we could add in the future. As a workaround, you can define your own custom indexer for prefabs that will index all the parent types with:

    Code (CSharp):
    1. [CustomObjectIndexer(typeof(GameObject))]
    2. static void IndexMyPrefabProperties(CustomObjectIndexerTarget context, ObjectIndexer indexer)
    3. {
    4.     if (!(context.target is GameObject prefab))
    5.         return;
    6.  
    7.     var gocs = prefab.GetComponents<Component>();
    8.     for (var componentIndex = 0; componentIndex < gocs.Length; ++componentIndex)
    9.     {
    10.         var c = gocs[componentIndex];
    11.         if (!c || c is not MonoBehaviour)
    12.             continue;
    13.         var baseType = c.GetType().BaseType;
    14.         while (baseType != null && baseType != typeof(MonoBehaviour))
    15.         {
    16.             indexer.IndexProperty(context.documentIndex, "t", baseType.Name, true, false);
    17.             baseType = baseType.BaseType;
    18.         }
    19.     }
    20. }
    Then, in the index manager select the index that indexes your prefabs (or the default one if you haven't setup any) and click build.
     
  28. nehvaleem

    nehvaleem

    Joined:
    Dec 13, 2012
    Posts:
    249
    Thanks for the reply and the snippet but unfortunately it didn't work in my case. I've added it to my codebase, rebuild the asset index, even cerated new index only (of prefabs type) and build that one too and still the search yields no results when searching for the base types. Is there an easy way to debug this or maybe some documentation about CustomObjectIndexer? I wasn't able to find too much about that one, and my project is pretty big, so the indexes are about 200mb in size, so you can imagine the time needed to build them :)
     
  29. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    5,966
    There's a bug in the code where it doesn't index the type itself, just the base types. Or maybe that's intentional, since that's already indexed by a different type?
     
  30. nehvaleem

    nehvaleem

    Joined:
    Dec 13, 2012
    Posts:
    249
    I am assuming that is because the indexing by the final type is handled by the default indexer. Also I am testing by searching for the base type and it doesn't return any results.
     
  31. nehvaleem

    nehvaleem

    Joined:
    Dec 13, 2012
    Posts:
    249
    What's even weirder: I've created an empty project and it seemed to work at first glance, but after I've refactored the BaseClass and changed its name, the index had the original name saved. Even deleting entire index and recreating it from scratch still showing it saved with original name.

    Example:
    I've created 2 classes:
    TestBaseClass
    &
    ExtendedSample
    (that derives from
    TestBaseClass
    , then created the prefab with the
    ExtendedSample
    . Next I have built the index and it seemed to work just fine, I was able to search for this prefab using
    t:TestBaseClass
    .

    Next I renamed
    TestBaseClass
    to
    ActionController
    along with the filename, let unity recompile, rebuilt index, deleted & created index again and it still showing:



    And that is probably why it didn't work in my original project. I am assuming that it doesn't work for the prefabs that are already indexed and some sort of artifacts are stored in the library folder.

    Even the simple
    Debug.Log
    aren't fired now for the
    CustomObjectIndexer
    , but it were for the first usage.
     
  32. sebastiengrenier

    sebastiengrenier

    Unity Technologies

    Joined:
    Jun 11, 2019
    Posts:
    72
    Yes, there seems to be a bug with the rebuild of the indexes, either try to reimport the prefabs, or last resort delete your Library folder. Even deleting the index doesn't solve all the problems because there seems to be lingering artifacts that prevent a fresh build, I will have to investigate this. One other thing I see is that we don't remove old entries from the index, so when you refactor the name of the class, the old entries referencing the old type are still there.

    If you want, you can log a bug so you can track the progress.
     
  33. nehvaleem

    nehvaleem

    Joined:
    Dec 13, 2012
    Posts:
    249
    Thanks for the info. Obviously deleting the Library folder is a no go for me, since it is around ~70GB. I'll log a bug report later tomorrow, thanks!
     
  34. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    5,966
    I just rebuilt the search index, and I got a million of these errors:

    upload_2022-6-2_8-42-9.png

    I have seen the same thing happen when reimporting the project or doing other operations that touch a bunch of assets, but I haven't actually seen it when I work with any individual asset. This isn't directly tied to quick search, but does anyone have any idea where I should go to figure out what's going on and why?
     
  35. MostHated

    MostHated

    Joined:
    Nov 29, 2015
    Posts:
    1,176
    Edit --
    Nevermind, I got it figured out. I discovered I could easily create a custom selector.

    Code (CSharp):
    1.     [SearchSelector("size", provider: providerId)]
    2.     internal static object GetSize(SearchItem item)
    3.     {
    4.         return item.ToObject<GameObject>().GetComponent<Renderer>().bounds.size.magnitude;
    5.     }

    ----

    I am attempting to create a table with a few columns using SearchColumn() and when searching GameObjects via the hierarchy provider (using 'size>x' to find objects larger than x), what would I need to use as the selector to display the size that was used as the criteria/calculation in the search as a column in a result table?

    As a wild stab in the dark I tried the following:

    Code (CSharp):
    1.  
    2. new SearchColumn("Size", "size", "size", null, flags) { width = 100f };
    3.  
    I was hoping it would follow suit with other examples, such as this, which did work.
    Code (CSharp):
    1.  
    2. new SearchColumn("Name", "name", "name", null, flags) { width = 150f };
    3.  
    It didn't work, though, unfortunately.

    Thanks,
    -MH
     
    Last edited: Jun 12, 2022
  36. MostHated

    MostHated

    Joined:
    Nov 29, 2015
    Posts:
    1,176
    One thing I have been trying to get working that I can't quite get yet is displaying a list of results without first searching them. Basically, providing an already created list of items to simply display. Is there a trick to this?

    Here was what I had most recently attempted as a test:

    Code (CSharp):
    1. List<Object> myList = new List<Object>();
    2. // -- Populate the list with the results ....
    3.  
    4. List<SearchItem> items = new List<SearchItem>();
    5.  
    6. var provider = new SearchServiceProvider();
    7.  
    8. myList.forEach(x =>
    9. {
    10.     items.Add(provider.CreateItem($"{x.name}_{x.GetInstanceID()}"));
    11. });
    12.  
    13. var context = provider.defaultContext;
    14. var group = new GroupedSearchList(context);
    15. group.AddItems(items);
    16. var view = new SearchResultView(group);
    17. context.searchView = view;
    18.  
    19. var qs = QuickSearch.Create<SearchPickerWindow>(context);
    20. qs.searchEventStatus = QuickSearch.SearchEventStatus.DoNotSendEvent;
    21. qs.titleContent.text = $"View...";
    22. qs.ShowWindow();
    It just displays the "Clear Results" item and none of the objects I created. Is this an appropriate approach to this?
    Thanks,
    -MH
     
  37. sebastiengrenier

    sebastiengrenier

    Unity Technologies

    Joined:
    Jun 11, 2019
    Posts:
    72
    Hi! I'm not sure what you are trying to achieve here. If you only wish to display a list of items without any of the "Search" capabilities, I would suggest to creating your own window with a simple list view. However, if you wish to be able to search your results, or just create a picker in which you can select items, here is what I would do:

    First, I would avoid using a GroupedSearchList and creating a new SearchResultView. It is not recommended to use the internal members. The "searchView" that you are assigning is getting overridden when the window is shown, and that is why you cannot see any results.

    Second, I would create my own SearchProvider. By creating your own SearchProvider, you can really control what you show on the screen and how the items are shown. Here are two examples of SearchProviders. The first one yields a set of static items that doesn't change, and can be used directly into the global Search window (uses the attribute SearchItemProvider). The second one has to be instantiated (and cannot be used by the global Search window), but you can set your results dynamically.
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEditor.Search;
    4.  
    5. public class ItemFromStaticSourceSearchProvider
    6. {
    7.     public const string Id = "item-from-source-search-provider";
    8.     public const string DisplayName = "Source";
    9.  
    10.     [SearchItemProvider]
    11.     public static SearchProvider CreateProvider()
    12.     {
    13.         return new SearchProvider(Id, DisplayName)
    14.         {
    15.             fetchItems = FetchItems
    16.         };
    17.     }
    18.  
    19.     static IEnumerator FetchItems(SearchContext context, List<SearchItem> items, SearchProvider provider)
    20.     {
    21.         var allResults = FetchAllResults();
    22.         foreach (var result in FilterResults(allResults, context))
    23.         {
    24.             yield return provider.CreateItem(context, result);
    25.         }
    26.     }
    27.  
    28.     static IEnumerable<string> FetchAllResults()
    29.     {
    30.         // Return all results
    31.         yield return "Bob";
    32.         yield return "Bobby";
    33.         yield return "Charles";
    34.     }
    35.  
    36.     static IEnumerable<string> FilterResults(IEnumerable<string> results, SearchContext context)
    37.     {
    38.         // Filter results based on search query
    39.         if (string.IsNullOrWhiteSpace(context.searchQuery))
    40.             return results;
    41.  
    42.         // Other filtering, either really simple like results.Where(...) or more complicated with a QueryEngine
    43.         return results;
    44.     }
    45. }
    46.  
    47. public class ItemFromListSearchProvider : SearchProvider
    48. {
    49.     public const string Id = "item-from-list-search-provider";
    50.     public const string DisplayName = "List";
    51.  
    52.     public IEnumerable<string> SourceItems { get; set; }
    53.  
    54.     public static ItemFromListSearchProvider CreateProvider(IEnumerable<string> source)
    55.     {
    56.         return new ItemFromListSearchProvider() { SourceItems = source };
    57.     }
    58.  
    59.     public ItemFromListSearchProvider()
    60.         : base(Id, DisplayName)
    61.     {
    62.         fetchItems = FetchItems;
    63.     }
    64.  
    65.     IEnumerator FetchItems(SearchContext context, List<SearchItem> items, SearchProvider provider)
    66.     {
    67.         foreach (var result in FilterResults(SourceItems, context))
    68.         {
    69.             yield return provider.CreateItem(context, result);
    70.         }
    71.     }
    72.  
    73.     static IEnumerable<string> FilterResults(IEnumerable<string> results, SearchContext context)
    74.     {
    75.         // Filter results based on search query
    76.         if (string.IsNullOrWhiteSpace(context.searchQuery))
    77.             return results;
    78.  
    79.         // Other filtering, either really simple like results.Where(...) or more complicated with a QueryEngine
    80.         return results;
    81.     }
    82. }
    83.  
    Here's how you can instantiate a Search Window using only those providers:
    Code (CSharp):
    1. using UnityEditor;
    2. using UnityEditor.Search;
    3. using UnityEngine;
    4.  
    5. public class PickerScript
    6. {
    7.     [MenuItem("Test/Show My ItemsFromStaticSource Picker")]
    8.     static void ShowItemsFromStaticSourcePicker()
    9.     {
    10.         var context = SearchService.CreateContext(ItemFromStaticSourceSearchProvider.Id, "");
    11.         var viewState = new SearchViewState(context)
    12.         {
    13.             windowTitle = new GUIContent("View...")
    14.         };
    15.         var qs = SearchService.ShowWindow(viewState);
    16.     }
    17.  
    18.     [MenuItem("Test/Show My ItemsFromList Picker")]
    19.     static void ShowItemsFromListPicker()
    20.     {
    21.         var results = new[] { "Bob", "Bobby", "Charles", "Cat", "Dog" };
    22.         var myProvider = ItemFromListSearchProvider.CreateProvider(results);
    23.         var context = SearchService.CreateContext(new[] { myProvider }, "");
    24.         var viewState = new SearchViewState(context)
    25.         {
    26.             windowTitle = new GUIContent("View...")
    27.         };
    28.         var qs = SearchService.ShowWindow(viewState);
    29.     }
    30. }
    31.  
    Here is an image showing the second provider in action:
    upload_2022-6-14_16-41-46.png

    If you wish to use the SearchPickerWindow, the only thing you would need to change would be
    SearchService.ShowWindow(viewState)
    to
    SearchService.ShowPicker(viewState)
    , and then set the corresponding
    selectHandler
    and
    trackingHandler
    on the SearchViewState.
     
    MostHated likes this.
  38. MostHated

    MostHated

    Joined:
    Nov 29, 2015
    Posts:
    1,176
    That's perfect, I definitely appreciate it.

    The main reason I wanted to use the search window over a custom window was I wanted to retain some of the additional functionality that it has without having to remake the wheel, and be able to utilize the table view / additional columns, etc. I have collections of items already that are created various ways and having a quick and customizable way to display them is great.
     
    sebastiengrenier likes this.
  39. MostHated

    MostHated

    Joined:
    Nov 29, 2015
    Posts:
    1,176
    Well, shoot. Entities 0.51 came out, I updated to Unity 2021, now half of the things I was using are internal, but since it's not a package anymore so I can't just use internalvisible.

    It's back to the drawing board now for the majority of the viewing tools I was making since I can't cast to QuickSearch to gain access to the resultView field, which is internal now too, it seems. Then I can't cast that to TableView anymore, or create a new SearchTable.

    It seems a bit... backwards, I guess, to have all these great and useful tools, then cut off access to them or restrict them in the first place?

    -- Edit
    I have been able to reflect a bunch of it so far, but that certainly isn't ideal. Are there any plans on making some of these items public? They are just too useful to keep internal.

    An example of what I am referring to is, I was using this Sample from the QuickSearch Extensions package, which I was able to base my current results viewer off, but moving to UnityEngine.Search, I was no longer able to use (my own custom version) without reflection.

    It's there as an example (Search/Table Example) yet you can't actually use it as an example, because SearchTable and SearchColumn are internal.

    Code (CSharp):
    1. using System.Collections.Generic;
    2. using UnityEngine;
    3.  
    4. namespace UnityEditor.Search
    5. {
    6.     static class TableExamples
    7.     {
    8.         [MenuItem("Search/Table Example")]
    9.         public static void OpenTableView()
    10.         {
    11.             var context = SearchService.CreateContext("scene", "path:turntable t=MeshFilter");
    12.             var viewState = new SearchViewState(context, new SearchTable("myColumnSetup", CreateColumns()));
    13.             SearchService.ShowWindow(viewState);
    14.         }
    15.  
    16.         static IEnumerable<SearchColumn> CreateColumns()
    17.         {
    18.             var flags = SearchColumnFlags.IgnoreSettings; // Set to SearchColumnFlags.Default if you want the system to restore any user changes to column's width
    19.             yield return new SearchColumn("Name", "name", "name", null, flags) { width = 250f };
    20.             yield return new SearchColumn("Mesh", "#m_Mesh", "ObjectReference", null, flags) { width = 180f };
    21.             yield return new SearchColumn("Vertices", "vertices", "default", null, flags) { width = 60f };
    22.             yield return new SearchColumn("Delete", null, null, null, flags) { width = 60f, drawer = OnDelete };
    23.         }
    24.  
    25.         private static object OnDelete(SearchColumnEventArgs args)
    26.         {
    27.             if (GUI.Button(args.rect, "Delete"))
    28.                 Debug.LogWarning($"TODO: Delete {args.item.GetLabel(args.context, true)}");
    29.             return args.value;
    30.         }
    31.     }
    32. }
     
    Last edited: Jun 17, 2022
  40. sebastiengrenier

    sebastiengrenier

    Unity Technologies

    Joined:
    Jun 11, 2019
    Posts:
    72
    Hi. Yes, many of the internal apis were made public in version 2022.2. I think some of those examples lack the proper
    #if UNITY_2022_2_OR_NEWER
    guard.
     
    MostHated likes this.
  41. TextusGames

    TextusGames

    Joined:
    Dec 8, 2016
    Posts:
    424
    How to change the size of "Transient window"? (2021.3.5f1.321)
    upload_2022-7-9_13-47-4.png
     
  42. TextusGames

    TextusGames

    Joined:
    Dec 8, 2016
    Posts:
    424
    New search window is shown at location of pinned serach window.

    Preferably new unpined search window should show itself at the position there last unpinned search window was shown. (Default is transient window position)

    upload_2022-7-9_14-58-14.png
     
  43. TextusGames

    TextusGames

    Joined:
    Dec 8, 2016
    Posts:
    424
    Search result count is not always correctly updated in tab name if multiple search windows are used.
    upload_2022-7-9_15-5-42.png
     
  44. SolidAlloy

    SolidAlloy

    Joined:
    Oct 21, 2019
    Posts:
    58
    Has the issue been created on Issue Tracker yet? Looking forward to using the table view but this decorator attributes issue (Header, Space, etc.) is killing me.
     
  45. Chaosed0

    Chaosed0

    Joined:
    Jun 19, 2013
    Posts:
    11
    Hi! Just recently found Quick Search, it is a really great tool :) I'm starting to use it all the time for
    t:
    searches on component types.

    I wanted to write a quick editor tool which leverages the search engine to show our designers what objects reference a given prefab. However, it appears that
    ref:
    searches return not only assets that directly depend on that asset, but also assets that indirectly depend on that asset. That means all sorts of unrelated assets will show up in a
    ref:
    search for an enemy, like build configurations (which reference scenes). Is there a way to search only for direct dependencies?

    And please correct me if I'm making an incorrect assumption here - this was based purely off of some quick and dirty code I wrote.
     
  46. sebastiengrenier

    sebastiengrenier

    Unity Technologies

    Joined:
    Jun 11, 2019
    Posts:
    72
    If you are using the "Window/Search/Transient Window" menu, you can't. If you use the api, you can set the width and height using
    SearchService.ShowWindow(defaultWidth: 600, defaultHeight: 400, dockable: false)
    .

    Good catch for these. Can you log a bug for each so we can easily track them?

    It seems the issue was closed by mistake. I'll try to talk to the QA to reopen it.

    ref:
    should return only the first level dependencies, unless there is something wrong with how we index this property. However, if you are getting unwanted results, maybe you could try to filter the types you want with
    t:
    , like
    (t:prefab or t:sceneasset)
    for a combination of types you wish to get.
     
  47. sama-van

    sama-van

    Joined:
    Jun 2, 2009
    Posts:
    1,692
    I just found something weird related to the search per layer in the scene.

    I got asset using the layers index : 5, 15, 25 in the scene.
    If I process a search using the layer:5 string it will return every layers including 5 in the idx...
    Did someone experienced the same issue and could confirm ?

    Package version : 2.0.2 (Unity 2019.4.39f1)
     
  48. sebastiengrenier

    sebastiengrenier

    Unity Technologies

    Joined:
    Jun 11, 2019
    Posts:
    72
    Hi! The problem you have is because you are using the ":" (contains) operator. This transforms the numerical values into strings and does a "Contains" operation. What you want to use is the "=" (equals) operator. This will make sure that only the objects that are in the layer equal to the value specified will show up.
     
  49. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    5,966
    What is the intended way to search from code?

    I've got something like this:
    Code (csharp):
    1. [MenuItem("Temp/Test")]
    2. public static void Test() {
    3.     SearchService.Request("SpriteShape", OnSearchCompleted, SearchFlags.Default);
    4. }
    5.  
    6. private static void OnSearchCompleted(SearchContext context, IList<SearchItem> items) {
    7.     Debug.Log(context);
    8.     foreach (var item in items) {
    9.         Debug.Log($"{item.ToObject()}", item.ToObject());
    10.     }
    11. }
    I'm getting the objects, which is fine and useable, but I'm missing quite a bit of info I know is in there! For example, when the SearchItems are assets, the
    SearchItem.data
    is an AssetMetaInfo struct. That struct has a bunch of useful data already calculated - the path of the asset, the type of the asset, etc. - but that struct is private, so I have to calculate that data myself by hitting the assetdatabase.

    Is there a way to use the SearchService or some other API to get the full amount of information available?
     
  50. sebastienp_unity

    sebastienp_unity

    Unity Technologies

    Joined:
    Feb 16, 2018
    Posts:
    97
    Hi Baste,

    as you notice the AssetMetaDataInfo class is private. We try to keep the api that we aren't sure about private to avoid supporting those for ever.

    That said, this class could be useful. I will bring this up to the team and we will see if we make the class public for next release. That said the SearchItem.data would stay of type object so you will have to cash it yourself.