Search Unity

AssetDatabase.FindAssets() returning repeated assets

Discussion in 'Asset Database' started by roberto_sc, Dec 5, 2019.

  1. roberto_sc

    roberto_sc

    Joined:
    Dec 13, 2010
    Posts:
    144
    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");
    2.    
    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()}");
    6.  
    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?

    ------------------------------------------------------------------------------
    EDIT

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