Search Unity

  1. 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
  2. Ever participated in one our Game Jams? Want pointers on your project? Our Evangelists will be available on Friday to give feedback. Come share your games with us!
    Dismiss Notice

AssetDatabase.FindAssets() returning repeated assets

Discussion in 'Scripting' started by roberto_sc, Dec 5, 2019.

  1. roberto_sc


    Dec 13, 2010
    I have around 2000 sprites in a project, I'm using AssetDatabase.FindAssets to find all of them, but it is returning repeated items.

    I use the following code to find the repeated items:

    Code (CSharp):
    1. var spriteGUIDS = AssetDatabase.FindAssets("t:Sprite");
    3. var repeatedItems = spriteGUIDS.GroupBy(x => x)
    4.     .Where(g => g.Count() > 1)
    5.     .Select(y => $"{AssetDatabase.GUIDToAssetPath(y.Key)} (GUID {y.Key} : {y.Count()}");
    7. foreach (var ri in repeatedItems)
    8. {
    9.     Debug.LogError(ri);
    10. }
    This is telling me that there are hundreds of repeated items - same path and same GUID. Some of them are repeated more than 60 times.

    Why does this happen?


    Obviously it happens because a texture can have more than one sprite.. <facepalm>
    Last edited: Dec 5, 2019
    Kurt-Dekker likes this.