Search Unity

  1. We are looking for feedback on the experimental Unity Safe Mode which is aiming to help you resolve compilation errors faster during project startup.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Quick Search Preview

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

  1. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    4,903
    Sure, you can freely mess with the part of the list that's not visible. I think you can also start rearranging things once I move back to the search field.
     
  2. 00christian00

    00christian00

    Joined:
    Jul 22, 2012
    Posts:
    836
    This tool looks super useful and super fast, love it.
    Is there a way to search for gameobjects containing specific components in the scene?
    I couldn't find a way.
     
  3. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    4,903
    h: gives a scene search, t: gives a type search.

    So it'd be
    h: t:MeshRenderer
    to search for mesh renderers in the open scenes.
     
    jonathans42 likes this.
  4. 00christian00

    00christian00

    Joined:
    Jul 22, 2012
    Posts:
    836
    Thanks very useful.

    It would be nice to browse the found gameobjects without closing the search window.
    Currently if I select the gameobject to check its properties it automatically close the window and focus the window on the object.
    Also the focus should be optional since it's just one hotkey away to focus on the object.
     
  5. jonathans42

    jonathans42

    Unity Technologies

    Joined:
    Jan 25, 2018
    Posts:
    261
    Hi,

    Which version are you using? Normally you should be able to select search results and inspect the item in the embedded inspector (this is available in >=1.6)

    upload_2020-6-10_13-45-23.png
     
    SlimeProphet and 00christian00 like this.
  6. 00christian00

    00christian00

    Joined:
    Jul 22, 2012
    Posts:
    836
    Thanks, I was on 1.5.4, didn't see there was some preview versions.
    The new one is really cool.
     
    jonathans42 likes this.
  7. jonathans42

    jonathans42

    Unity Technologies

    Joined:
    Jan 25, 2018
    Posts:
    261
    Quick Search 2.0 (which is basically 1.6.0-preview.9) will be released in the upcoming weeks.
     
    00christian00 likes this.
  8. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    2,884
    Does quicksearch have query syntax like
    -type:camera +type:rigid*
    ?
     
  9. SlimeProphet

    SlimeProphet

    Joined:
    Sep 30, 2019
    Posts:
    27
    This is a really great addition! I would suggest only two things: (1) intelligent ordering of results, going from "things you most likely want to open to things least likely to want to open," for example, prefabs should appear above animation assets and user-created content above internal stuff; and (2) the Tab key should go from search bar to results in addition to the down-arrow key.
     
  10. jonathans42

    jonathans42

    Unity Technologies

    Joined:
    Jan 25, 2018
    Posts:
    261
    You can use
    -
    to exclude resutls and instead of
    type:
    use
    t:


    Also when you use
    :
    it does partial mathcing as with
    =
    it do exact match.

    In example if you do
    -t:camera t:rigid
    in the scene view, this will match game objects without a component that starts with "camera" but with a
    RigidBody
    component.

    As if you do,
    -t="CameraCustom"
    , this will match game objects with a
    Camera
    component but without a
    CameraCustom
    component since you are using
    =
    .
     
    laurentlavigne likes this.
  11. jonathans42

    jonathans42

    Unity Technologies

    Joined:
    Jan 25, 2018
    Posts:
    261
    Hi, thanks for the feedback.

    We still to improve the sorting of results and even add more control to the user to select which type of sorting he would like to use. This will come in future versions.

    In the next version the Tab key will pop an "intelligent" auto-complete dropdown that will propose filters and words to complete the query based on what you have already typed.

    Pressing key down to start selecting results is not enough for you?
     
    SlimeProphet likes this.
  12. 00christian00

    00christian00

    Joined:
    Jul 22, 2012
    Posts:
    836
    Hi, It would be useful to have the option to check side by side the values of the selected items instead of grouping them like the image.
     
  13. jonathans42

    jonathans42

    Unity Technologies

    Joined:
    Jan 25, 2018
    Posts:
    261
    A future version of Quick Search will probably include a table view to bulk edit and compare many search results.
     
    00christian00 likes this.
  14. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    2,884
    Nice.
    This should be in the search field, in faded, there is enough room
     
  15. nehvaleem

    nehvaleem

    Joined:
    Dec 13, 2012
    Posts:
    48
    Hi! thanks for this amazing piece of work!

    I've got one question tho - is it possible to make a Quick Search appear after double tap at some key? I would like to make it popup after double space tap, but I don't think it is possible with the current shortcuts manager.
     
  16. fffMalzbier

    fffMalzbier

    Joined:
    Jun 14, 2011
    Posts:
    3,066
    Last edited: Jun 17, 2020
  17. oxysofts

    oxysofts

    Joined:
    Dec 17, 2015
    Posts:
    73
    Beautiful work on the new features! I love that I can scale down the UI until it's very minimal and each line is very thin, and I also really like the control we have with the index. (as long as it works properly, there was a situation recently where the index took a while to update after I created an asset) Using the index config I've been able to strip out the .cs files from the search!
     
  18. oxysofts

    oxysofts

    Joined:
    Dec 17, 2015
    Posts:
    73
    Right now there is a consistent and reproducible Unity crash related to Quick Search:

    Unity 2019.4.0f1

    1. Open a prefab with a script that has 2 unset fields.
    2. Disable prefab mode auto-save.
    3. Open Quick Search and find an asset to fill the first field.
    4. Open Quick Search again to fill the second field.
    5. Unity Crash when opening Quick Search for the second time.

    Is this reproducible for anyone else?
     
  19. sebastienp_unity

    sebastienp_unity

    Unity Technologies

    Joined:
    Feb 16, 2018
    Posts:
    34
  20. sebastienp_unity

    sebastienp_unity

    Unity Technologies

    Joined:
    Feb 16, 2018
    Posts:
    34
    Thanks for the good feedback. Always good to hear a customer is satisfied :)

     
  21. fffMalzbier

    fffMalzbier

    Joined:
    Jun 14, 2011
    Posts:
    3,066
    Looks like the documentation needs a update.

    A general / easy changeable URL searcher would be nice.
     
    Last edited: Jun 19, 2020
  22. oxysofts

    oxysofts

    Joined:
    Dec 17, 2015
    Posts:
    73
    It looks like there has been a regression in 2.0: it's necessary to hit the down key before the first item can be invoked, whereas it was pre-selected by default in the past.
     
  23. Red_Dragon69

    Red_Dragon69

    Joined:
    Sep 7, 2015
    Posts:
    71
    Hi, is there a possibility that the keyboard localisation isn't working correctly? I'm using a german keyboard and the combination of Alt + ' doesn't work. Instead I have to press Alt + ä to make the quicksearch window pop up. Happens in Unity 2019.4.0f1 and quicksearch package version 2.0.0
     
  24. jonathans42

    jonathans42

    Unity Technologies

    Joined:
    Jan 25, 2018
    Posts:
    261
    I'll look at this issue. Do you think you can report a bug so we make sure it gets resolved ASAP.
     
  25. jonathans42

    jonathans42

    Unity Technologies

    Joined:
    Jan 25, 2018
    Posts:
    261
    It is possible the Shortcut Manager doesn't map your keyboard successfully. You can always go in the Shortcut Manager and bind another shortcut to open Quick Search.

    upload_2020-6-23_20-35-24.png
     
  26. jonathans42

    jonathans42

    Unity Technologies

    Joined:
    Jan 25, 2018
    Posts:
    261
    Yes the documentation needs to be updated for 2.0. It is still mapped to 1.5. We are working on it.
     
    fffMalzbier likes this.
  27. jonathans42

    jonathans42

    Unity Technologies

    Joined:
    Jan 25, 2018
    Posts:
    261
    I cannot seem to repro locally. Do you mind reporting us a bug with a project in which you repro the issue and we'll look at it.
     
  28. oxysofts

    oxysofts

    Joined:
    Dec 17, 2015
    Posts:
    73
    In that case it must be something unique to our project. This is a large project 4 years in the making with no shortage of plugins and editor extensions, so I wouldn't be surprised if one or a combination of them is responsible. I'll try investigating a bit on my side to see if I can figure out the specifics.

    Done! case #1258382
     
  29. jonathans42

    jonathans42

    Unity Technologies

    Joined:
    Jan 25, 2018
    Posts:
    261
    Assigned to me. It should get fixed shortly. Lookout for 2.0.2, as 2.0.1 will be a hotfix release to remove experimental namespace usages.
     
    oxysofts likes this.
  30. oxysofts

    oxysofts

    Joined:
    Dec 17, 2015
    Posts:
    73
    How do you guys feel about packaging an official 'Selection History' search provider out of the box with Quick Search? This feature has been high in demand for years in Unity and Quick Search seems like a perfect match for this!
     
  31. jonathans42

    jonathans42

    Unity Technologies

    Joined:
    Jan 25, 2018
    Posts:
    261
    This seems like a nice thing to have. Did you already made one we could look at?
     
  32. Red_Dragon69

    Red_Dragon69

    Joined:
    Sep 7, 2015
    Posts:
    71
    @jonathans42 jep, you're right. The keyboard is possibly not mapped the right way. Is it possible that there'll be correct keyboard localisation when defining the shortcuts? Already assigned a (for me) more convenient shortcut, thanks for the hint :)
     
  33. TorTales

    TorTales

    Joined:
    Aug 3, 2017
    Posts:
    1
    I have the same problem on all projects and it's really frustrating. I only just started using quick search so I didn't know it used to be different.
     
  34. jonathans42

    jonathans42

    Unity Technologies

    Joined:
    Jan 25, 2018
    Posts:
    261
    Next release (2.0.2) will have this issue fixed. Pressing enter with no explicit selection with execute the default action of the first result in the list.
     
    Last edited: Jul 1, 2020
    TorTales and oxysofts like this.
  35. oxysofts

    oxysofts

    Joined:
    Dec 17, 2015
    Posts:
    73
    I have indeed started on one 2-3 weeks ago, however it's quite buggy and needs a lot of work still.

    Code (CSharp):
    1.  
    2. using System;
    3. using System.Collections.Generic;
    4. using System.IO;
    5. using System.Linq;
    6. using Anjin.Util;
    7. using JetBrains.Annotations;
    8. using Unity.QuickSearch;
    9. using UnityEditor;
    10. using UnityEditor.ShortcutManagement;
    11. using UnityEditorInternal;
    12. using UnityEngine;
    13. using Object = UnityEngine.Object;
    14.  
    15. namespace AnjinEditor.QuickSearch
    16. {
    17.    [UsedImplicitly]
    18.    public class RecentAssetSearching
    19.    {
    20.       private static Object[] _lastDraggedObjects;
    21.  
    22.       private const int BUFFER_SIZE = 25;
    23.  
    24.       static RecentAssetSearching()
    25.       {
    26.          Config.InternalEditor.SelectionHistory.RemoveAll(group => group == null || group.All(item => item == null));
    27.  
    28.          Selection.selectionChanged += () =>
    29.          {
    30.             List<Object[]> history = Config.InternalEditor.SelectionHistory;
    31.  
    32.             int i = history.IndexOf(Selection.objects);
    33.             if (i > -1)
    34.             {
    35.                history.RemoveAt(i);
    36.             }
    37.  
    38.             history.Insert(0, Selection.objects);
    39.  
    40.             while (history.Count >= BUFFER_SIZE)
    41.             {
    42.                history.RemoveAt(BUFFER_SIZE - 1);
    43.             }
    44.          };
    45.       }
    46.  
    47.       [Shortcut("Recent Assets", KeyCode.RightAlt)]
    48.       private static void RecentAssetsShortcut()
    49.       {
    50.          Unity.QuickSearch.QuickSearch quicksearch = Unity.QuickSearch.QuickSearch.OpenWithContextualProvider("recent_assets");
    51.          quicksearch.SetSearchText("r:");
    52.       }
    53.  
    54.       [SearchItemProvider, UsedImplicitly]
    55.       private static SearchProvider CreateProvider()
    56.       {
    57.          return new SearchProvider("recent_assets", "Recent Assets")
    58.          {
    59.             priority           = 100,
    60.             filterId           = "r:",
    61.             showDetails        = true,
    62.             showDetailsOptions = ShowDetailsOptions.Default | ShowDetailsOptions.Preview | ShowDetailsOptions.Inspector,
    63.  
    64.             fetchItems     = (context, list, provider) => FetchItems(context, provider),
    65.             toObject       = (item,    type) => AssetDatabase.LoadAssetAtPath(item.id, type),
    66.             trackSelection = (item,    context) => PingAsset(item.data as Object),
    67.             fetchThumbnail = (item,    context) => GetAssetThumbnail(item.data as Object),
    68.             fetchPreview   = (item,    context, size, options) => GetAssetPreview(item.data as Object, options),
    69.             startDrag      = StartDrag,
    70.          };
    71.       }
    72.  
    73.       public static Texture2D GetAssetThumbnail(Object obj)
    74.       {
    75.          if (!AssetDatabase.IsMainAsset(obj)) return null;
    76.  
    77.          string assetGUID = obj.GetAssetGUID();
    78.          string assetPath = AssetDatabase.GUIDToAssetPath(assetGUID);
    79.  
    80.          Texture2D thumbnail = AssetDatabase.GetCachedIcon(assetPath) as Texture2D;
    81.          return thumbnail ? thumbnail : InternalEditorUtility.FindIconForFile(assetPath);
    82.       }
    83.  
    84.       public static Texture2D GetAssetPreview(Object obj, FetchPreviewOptions previewOptions)
    85.       {
    86.          Texture2D tex = obj as Texture2D;
    87.          if (tex)
    88.             return tex;
    89.  
    90.          if (previewOptions.HasFlag(FetchPreviewOptions.Large) && obj is AudioClip)
    91.             return null;
    92.  
    93.          Texture2D preview = AssetPreview.GetAssetPreview(obj);
    94.  
    95.          if (preview == null || previewOptions.HasFlag(FetchPreviewOptions.Large))
    96.          {
    97.             Texture2D largePreview = AssetPreview.GetMiniThumbnail(obj);
    98.             if (preview == null || largePreview != null && largePreview.width > preview.width)
    99.                preview = largePreview;
    100.          }
    101.  
    102.          return preview;
    103.       }
    104.  
    105.       internal static void PingAsset(Object obj)
    106.       {
    107.          if (obj == null) return;
    108.          EditorGUIUtility.PingObject(obj);
    109.  
    110.          if (obj is GameObject) return;
    111.          Resources.UnloadAsset(obj);
    112.       }
    113.  
    114.       private static void StartDrag(SearchItem item, SearchContext context)
    115.       {
    116.          if (context.selection.Count > 1)
    117.          {
    118.             IEnumerable<Object> selectedObjects = context.selection.Select(i => AssetDatabase.LoadAssetAtPath<Object>(i.id));
    119.             string[]            paths           = context.selection.Select(i => i.id).ToArray();
    120.  
    121.             StartDrag(selectedObjects.ToArray(), paths, item.GetLabel(context, true));
    122.          }
    123.          else
    124.          {
    125.             StartDrag(new[] {AssetDatabase.LoadAssetAtPath<Object>(item.id)}, new[] {item.id}, item.GetLabel(context, true));
    126.          }
    127.       }
    128.  
    129.       internal static void StartDrag(Object[] objects, string[] paths, string label = null)
    130.       {
    131.          _lastDraggedObjects = objects;
    132.          if (paths == null || paths.Length == 0)
    133.             return;
    134.          DragAndDrop.PrepareStartDrag();
    135.          DragAndDrop.objectReferences = _lastDraggedObjects;
    136.          DragAndDrop.paths            = paths;
    137.          DragAndDrop.StartDrag(label);
    138.       }
    139.  
    140.       private static IEnumerable<SearchItem> FetchItems(SearchContext context, SearchProvider provider)
    141.       {
    142.          List<Object[]> history = Config.InternalEditor.SelectionHistory;
    143.  
    144.          for (int index = 0; index < history.Count; index++)
    145.          {
    146.             Object[]   objects = history[index];
    147.             SearchItem item    = SearchItem.none;
    148.  
    149.             if (objects.Length == 1)
    150.             {
    151.                // Just one object
    152.                // ========================================
    153.  
    154.                Object obj = objects[0];
    155.                if (!string.IsNullOrEmpty(AssetDatabase.GetAssetPath(obj)))
    156.                {
    157.                   // Is an asset
    158.                   // ----------------------------------------
    159.  
    160.                   string path = AssetDatabase.GUIDToAssetPath(obj.GetAssetGUID());
    161.  
    162.                   item = provider.CreateItem(context, path, 0, Path.GetFileName(path), null, null, null);
    163.  
    164.                   string sizeString = null;
    165.                   if (!AssetDatabase.IsValidFolder(path))
    166.                   {
    167.                      // Not a folder
    168.  
    169.                      FileInfo fi = new FileInfo(path);
    170.                      if (fi.Exists)
    171.                      {
    172.                         long fileSize = new FileInfo(path).Length;
    173.                         sizeString = $"{EditorUtility.FormatBytes(fileSize)}";
    174.                      }
    175.                      else
    176.                      {
    177.                         sizeString = "File does not exist anymore.";
    178.                      }
    179.                   }
    180.  
    181.                   item.description = $"{index + 1}: {path} ({sizeString})";
    182.                }
    183.                else
    184.                {
    185.                   // Is a scene object
    186.                   // ----------------------------------------
    187.                   item = provider.CreateItem(context,
    188.                                        obj.GetInstanceID().ToString(),
    189.                                        0,
    190.                                        $"{index + 1}: {obj.name}",
    191.                                        null,
    192.                                        null,
    193.                                        null);
    194.                }
    195.  
    196.                string words         = context.searchPhrase;
    197.                string filenameNoExt = obj.name;
    198.  
    199.                item.score = history.Count - index;
    200.                if (filenameNoExt.Equals(words, StringComparison.OrdinalIgnoreCase))
    201.                   item.score = history.Count + 1000;
    202.  
    203.                item.data = obj;
    204.             }
    205.             else
    206.             {
    207.                // A group of objects (multi selection)
    208.                // ========================================
    209.                // TODO
    210.             }
    211.  
    212.             yield return item;
    213.          }
    214.       }
    215.    }
    216. }
    217.  
    Couple of things...

    - Code's a bit messy since I was planning to work more on it.
    - I copied over a few internal functions from Quick Search, like
    GetAssetThumbnail
    and
    StartDrag
    .
    - Multi-selections aren't supported yet.
    - Executing an entry doesn't re-select it. (wasn't quite sure how to hook an item's execution event, actually)
    - Searching through the results has to be implemented manually it looks like?
    - There is some times an exception about accessing an
    Object
    that is already destroyed when navigating through the results. (just noticed, I think the culprit would be the last line in
    PingObject
    . I guess that's what I get for copy-pasting blindly!)
    -
    InternalEditor
    is a
    ScriptableObject
    in our project that we use to store long-term editor information through assembly reloads and editor restarts. (so it is used here to persist the selection history)
     
    Last edited: Jul 2, 2020
    jonathans42 likes this.
  36. Alexis-Dev

    Alexis-Dev

    Joined:
    Apr 16, 2019
    Posts:
    56
    Hello there!

    I have a question about this awesome package!
    Can we find where an asset is used? I mean if I search a material, I can find every asset use it in the project?

    Best,
    Alexis
     
  37. jonathans42

    jonathans42

    Unity Technologies

    Joined:
    Jan 25, 2018
    Posts:
    261
    If you enable dependency indexing for your asset indexes (version >=2.0):

    Open up index manager:
    upload_2020-7-3_12-25-36.png

    Then make sure to enable the option Dependencies for your index:

    upload_2020-7-3_12-26-23.png

    Then you can use
    ref:something
    to find any asset that has a reference to "
    something
    "

    upload_2020-7-3_12-29-31.png

    You can use
    ref
    with
    =
    , i.e.
    ref="full/path"
    to be explicit and get exact matches:

    upload_2020-7-3_12-30-45.png
     
    Alexis-Dev likes this.
  38. jonathans42

    jonathans42

    Unity Technologies

    Joined:
    Jan 25, 2018
    Posts:
    261
    Once you have a query setup to find references, you can create a search expression and set some variables that can be easily changed to something:

    Create the expression
    upload_2020-7-3_12-48-33.png

    Then edit the expression to have something like this:

    upload_2020-7-3_12-48-55.png

    Then save it and select it in the project browser to have it displayed in the inspector, that way you can quickly change the variable "Asset Path" to any other asset:

    upload_2020-7-3_12-51-14.png

    Using Search Expression is a nice way to quickly retrieve something based a more complex query graph.
     
  39. Alexis-Dev

    Alexis-Dev

    Joined:
    Apr 16, 2019
    Posts:
    56
    Thank you very much for these precisions!
    That help me a lot, great job!

    Best,
    Alexis
     
    jonathans42 likes this.
unityunity