Search Unity

Is there a problem with the behavior of AssetDatabase.LoadAllAssetsAtPath in OnPostprocessModel in

Discussion in 'Asset Database' started by tnoji, Apr 22, 2021.

  1. tnoji

    tnoji

    Joined:
    Feb 21, 2017
    Posts:
    2
    It seems that the behavior of AssetDatabase.LoadAllAssetsAtPath in OnPostprocessModel of Unity2019.4.21f1 is different from the past version.

    in Unity2018.4.12f1
    Code (CSharp):
    1.     // g is FBX model
    2.     void OnPostprocessModel(GameObject g)
    3.     {
    4.         var modelImporter = assetImporter as ModelImporter;
    5.  
    6.         // SubAssets are retrieved.
    7.         var assets = AssetDatabase.LoadAllAssetsAtPath(modelImporter.assetPath);
    8.     }
    9.  
    in Unity2019.4.21f1
    Code (CSharp):
    1.     void OnPostprocessModel(GameObject g)
    2.     {
    3.         var modelImporter = assetImporter as ModelImporter;
    4.  
    5.         // array is empty.
    6.         var assets = AssetDatabase.LoadAllAssetsAtPath(modelImporter.assetPath);
    7.     }
    8.  
    but....

    in Unity2019.4.21f1
    Code (CSharp):
    1.     async void OnPostprocessModel(GameObject g)
    2.     {
    3.         await Task.Delay(100);
    4.  
    5.         var modelImporter = assetImporter as ModelImporter;
    6.  
    7.         // SubAssets are retrieved.
    8.         var assets = AssetDatabase.LoadAllAssetsAtPath(modelImporter.assetPath);
    9.     }
    10.  
    Did you change the specifications in Unity 2019?
     
  2. Adrian

    Adrian

    Joined:
    Apr 5, 2008
    Posts:
    1,065
    I think the issue is that the post processor is running during the import and it's only coincidence if other assets have already been imported and are available or not.

    I'm not sure what exactly you're trying to do but you're not really supposed to depend on anything but the current asset in a post processor, it can e.g. get you in trouble with the Cache Server:
    That's also why Unity added ScriptedImporter in 2020.2, which is able to declare dependencies let Unity order the imports so that they will be available in time.
     
    tnoji likes this.