Search Unity

How to find object by GUID in project window

Discussion in 'Editor & General Support' started by Stranger-Games, Jul 22, 2016.

  1. Stranger-Games

    Stranger-Games

    Joined:
    May 10, 2014
    Posts:
    393
    Hi,

    I have guids of objects serialized in an asset that I cannot use anymore.
    Now, I want to know which assets have that GUID in the project window.

    Is there a way to search like this guid: 2323423434234234
    I know I can type something like 't:texture' to get all textures, but is there a way to get the files with specific GUID?

    Any help is greatly appreciated.
     
    Xarbrough likes this.
  2. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,562
    You should have a look at the AssetDatabase class (available in editor code only).

    There are a few methods that deal with asset GUIDs:
    AssetDatabase.GUIDToAssetPath will return the path to an asset, given its GUID.

    There's also FindAssets that will accept a search query and will return an array of GUIDs. You can then further process these GUIDs with the method above to find the path.
     
    hhoffren likes this.
  3. Stranger-Games

    Stranger-Games

    Joined:
    May 10, 2014
    Posts:
    393
    Thank you for taking the time to answer.
    But I am trying to search in the editor, and not by writing code.
    Perhaps I will have to write a script to get what I needed to know.
     
  4. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,562
    The editor doesn't have this functionality built-in. The only way (i know) you can expose this functionality is to use these APIs and create something of your own.
     
    Stranger-Games likes this.
  5. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    973
    I was just in a need to locate some assets with specific guid, so I needed a menu with a textfield to paste the searched guid, so I wrote this script:
    Code (CSharp):
    1. using UnityEditor;
    2. using UnityEngine;
    3.  
    4. public class GUIDToAssetPath : EditorWindow
    5. {
    6.     string guid = "";
    7.     string path = "";
    8.     [MenuItem("APIExamples/GUIDToAssetPath")]
    9.     static void CreateWindow()
    10.     {
    11.         GUIDToAssetPath window = (GUIDToAssetPath)EditorWindow.GetWindowWithRect(typeof(GUIDToAssetPath), new Rect(0, 0, 400, 120));
    12.     }
    13.  
    14.     void OnGUI()
    15.     {
    16.         GUILayout.Label("Enter guid");
    17.         guid = GUILayout.TextField(guid);
    18.         GUILayout.BeginHorizontal();
    19.         GUILayout.FlexibleSpace();
    20.         if (GUILayout.Button("Get Asset Path",GUILayout.Width(120)))
    21.             path = GetAssetPath(guid);
    22.         GUILayout.FlexibleSpace();
    23.         GUILayout.EndHorizontal();
    24.         GUILayout.BeginHorizontal();
    25.         GUILayout.FlexibleSpace();
    26.         if (GUILayout.Button("Abort", GUILayout.Width(120)))
    27.             Close();
    28.         GUILayout.FlexibleSpace();
    29.         GUILayout.EndHorizontal();
    30.         GUILayout.Label(path);
    31.     }
    32.     static string GetAssetPath(string guid)
    33.     {
    34.         string p = AssetDatabase.GUIDToAssetPath(guid);
    35.         Debug.Log(p);
    36.         if (p.Length == 0) p = "not found";
    37.         return p;
    38.     }
    39. }
    40.  
     
    akuno, NotaNaN, ksf000 and 10 others like this.
  6. ErikH2000

    ErikH2000

    Joined:
    Apr 30, 2014
    Posts:
    13
    @tomekkie2, thanks a lot! I dropped the code into a new gameobject and it immediately worked.
     
    tomekkie2 likes this.
  7. N1kel

    N1kel

    Joined:
    Jun 27, 2013
    Posts:
    5
    you don't have to drop it on gameobject, you can put it a folder named "Editor" anywhere in the project and you should see the menu.
     
    tomekkie2 likes this.
  8. dpt2

    dpt2

    Joined:
    Jun 15, 2021
    Posts:
    50
    Thanks! Still great in 2021.
     
  9. jonathans42

    jonathans42

    Unity Technologies

    Joined:
    Jan 25, 2018
    Posts:
    514
    Hi, in case you do not want to add a new code snippet for this in your project you can use the new search window to search by guid, i.e.

    upload_2021-8-18_8-52-3.png
     
  10. dpt2

    dpt2

    Joined:
    Jun 15, 2021
    Posts:
    50
    Last edited: Aug 19, 2021
  11. jonathans42

    jonathans42

    Unity Technologies

    Joined:
    Jan 25, 2018
    Posts:
    514
    We now only officially support >=2020.3 for QuickSearch 3.0

    If I remember correctly, version 2.0 of the package also supports search by GUID, but indeed, the UI and UX is different. Also this version has less features.
     
    Stranger-Games likes this.
  12. dpt2

    dpt2

    Joined:
    Jun 15, 2021
    Posts:
    50
    -__- you folks deprecate Unity version features way too fast.
     
  13. vladboroday

    vladboroday

    Joined:
    Jan 3, 2018
    Posts:
    5
    If i was to change a scene, how would i find affected gameobjects using source control systems using Quick Search??(Sublime Merge for instance) upload_2021-10-22_14-43-36.png
     
  14. wadeowenwatt

    wadeowenwatt

    Joined:
    Oct 23, 2021
    Posts:
    1
    hmm i put it in a "Editor" folder, but how to run it :( (Update) Ohhh i can see that :v thank you so much..
     
  15. oOtroyOo

    oOtroyOo

    Joined:
    Jun 7, 2015
    Posts:
    4
  16. ina

    ina

    Joined:
    Nov 15, 2010
    Posts:
    1,085
    does guid search still work in unity 2022.3?