Search Unity

AssetDatabase.FindAssets during IPreprocessBuildWithReport

Discussion in 'Asset Database' started by print_helloworld, Mar 28, 2021.

  1. print_helloworld

    print_helloworld

    Joined:
    Nov 14, 2016
    Posts:
    231
    I wasnt sure where to ask this since this is more related to continuous integration setups.
    This is what my pre process script looks like:

    Code (CSharp):
    1. public class PreBuildProcess : IPreprocessBuildWithReport
    2. {
    3.     int IOrderedCallback.callbackOrder => int.MaxValue;
    4.  
    5.     void IPreprocessBuildWithReport.OnPreprocessBuild(BuildReport report)
    6.     {
    7.         AssetDatabase.Refresh(ImportAssetOptions.ForceSynchronousImport);
    8.         AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate);
    9.         AssetDatabase.Refresh(ImportAssetOptions.ImportRecursive);
    10.         AssetDatabase.SaveAssets();
    11.  
    12.         //find all and print the data
    13.         StringBuilder debugText = new StringBuilder();
    14.         string[] allGameObjects = AssetDatabase.FindAssets("t:GameObject");
    15.         foreach (string guid in allGameObjects)
    16.         {
    17.             string path = AssetDatabase.GUIDToAssetPath(guid);
    18.             debugText.Append(guid);
    19.             debugText.Append(" = ");
    20.             debugText.AppendLine(path);
    21.         }
    22.  
    23.         Debug.Log(debugText.ToString());
    24.     }
    25. }
    This gets invoked when the editor is told to make a build via CLI with no extra arguments to run anything, so this script pretty runs because of unitys build process. The print out of the information only prints prefabs inside the Packages/ folder and not any inside the Assets/ folder. The script itself is part of the Assets/ folder too and its not an external package. I tried different variations of Refresh, SaveAssets, callback orders and I'm not sure what I'm doing wrong. I've had this occur in other projects as well doing this exact thing.

    My only hypothetical work around is manually scrape the project folder, and to manually load the prefabs directly using System.IO api. Any help is appreciated.
     
  2. print_helloworld

    print_helloworld

    Joined:
    Nov 14, 2016
    Posts:
    231
    Turns out its symlinked assets, good to know that unity's asset database doesnt handle symlinked folders and files with CI setups