Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

AssetImporter.GetAtPath() never returns

Discussion in 'Editor & General Support' started by pjohalloran, Dec 2, 2015.

  1. pjohalloran

    pjohalloran

    Joined:
    Jan 11, 2013
    Posts:
    19
    Hi,

    I am on Unity 5.3.0.f2. I am seeing an issue with AssetImporter.GetAtPath() in certain situations.

    I have an editor script that generates asset bundle variants and directories.
    Code (CSharp):
    1.         private static List<string> CreateVariantDirectories(string assetBundleBaseName, string managedDirectory, MasterVariantIndex variantIndex, out bool neededToCreateDir) {
    2.             neededToCreateDir = false;
    3.  
    4.             List<string> variantDirectoryNames = new List<string>(variantIndex.VariantConfigurations.Count);
    5.             List<string> dirTypes = new List<string>(3) {
    6.                 AssetBundleVariantUtils.HDDir,
    7.                 AssetBundleVariantUtils.MDDir,
    8.                 AssetBundleVariantUtils.LDDir
    9.             };
    10.  
    11.             foreach(VariantConfiguration config in variantIndex.VariantConfigurations) {
    12.                 string platformDir = Path.Combine(managedDirectory, config.Platform.ToString());
    13.                 AssetBundleEditorUtils.CreateDirectory(managedDirectory, config.Platform.ToString());
    14.  
    15.                 foreach(string dirType in dirTypes) {
    16.                     string assetBundleName = assetBundleBaseName;
    17.                     string assetBundleVariantName = string.Format("{0}_{1}", dirType.ToLower(), config.Name.ToLower());
    18.                     string dirname = string.Format("{0}.{1}", assetBundleName, assetBundleVariantName);
    19.  
    20.                     bool created = AssetBundleEditorUtils.CreateDirectory(platformDir, dirname);
    21.                     neededToCreateDir = neededToCreateDir || created;
    22.                    
    23.                    AssetDatabase.Refresh();
    24.  
    25.                     string variantPath = Path.Combine(platformDir, dirname);
    26.  
    27.                    Debug.LogError("beforeGetAtPath");
    28.                    AssetImporterimp=AssetImporter.GetAtPath(variantPath);
    29.                    Debug.LogError("afterGetAtPath");
    30.                    imp.assetBundleName=assetBundleName;
    31.                    imp.assetBundleVariant=assetBundleVariantName;
    32.  
    33.                     variantDirectoryNames.Add(variantPath);
    34.                 }
    35.             }
    36.  
    37.             AssetDatabase.Refresh();
    38.  
    39.             return variantDirectoryNames;
    40.         }
    This is a function which partly does that.If I wrap this in a call like so with AssetDatabase Start and Stop Editing.

    Code (CSharp):
    1. AssetDatabase.StartAssetEditing();
    2. CreateVariantDirectories(...);
    3. AssetDatabase.StopAssetEditing();
    Then it falls over and editor script seems to become non responsive at AssetImporter.GetAtPath(variantPath);

    If I do not use StartAssetEditing and StopAssetEditing however, it runs ok. But really slow due to the multiple import steps. Is this a bug or am I doing something wrong?
     
  2. pjohalloran

    pjohalloran

    Joined:
    Jan 11, 2013
    Posts:
    19
    I figured out that maybe AssetImporter.GetAtPath is hanging as i have created new assets/directories but have not done an AssetDatabase.Refresh() to ensure the asset is picked up by unity editor. (As import is disabled by calling StartAssetEditing() ).

    So have changed around my code to do that. But should AssetImporter.GetAtPath() still hang though under these conditions?
     
    Elyaradine and Echo____G like this.