Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Regression: EditorUtility.CollectDependencies always returning null (Case 1179898)

Discussion in '2019.3 Beta' started by julian-moschuering, Aug 28, 2019.

  1. julian-moschuering

    julian-moschuering

    Joined:
    Apr 15, 2014
    Posts:
    529
    (Case 1179898) - Unity 2019.3.0b1:
    EditorUtility.CollectDependencies now always returns null independent of input.
     
    DeliaF_Manea likes this.
  2. julian-moschuering

    julian-moschuering

    Joined:
    Apr 15, 2014
    Posts:
    529
    For anyone interested: Workaround using the new API's:

    Code (CSharp):
    1. static HashSet<AssetPath> GetDependencies(string assetPath, BuildTarget buildTarget, TypeDB typeDB)
    2. {
    3.     var guid = new GUID(AssetDatabase.AssetPathToGUID(assetPath));
    4.     var ids = ContentBuildInterface.GetPlayerObjectIdentifiersInAsset(guid, buildTarget);
    5.     var deps = ContentBuildInterface.GetPlayerDependenciesForObjects(ids, buildTarget, typeDB);
    6.  
    7.     var dependencies = new HashSet<string>();
    8.     foreach (var dep in deps)
    9.     {
    10.         var path = "";
    11.         if (dep.fileType == FileType.SerializedAssetType)
    12.             path = dep.filePath;
    13.         else if (dep.fileType == FileType.MetaAssetType)
    14.             path = AssetDatabase.GUIDToAssetPath(dep.guid.ToString());
    15.  
    16.         if (string.IsNullOrEmpty(path))
    17.             continue;
    18.  
    19.         dependencies.Add(path);
    20.     }
    21.     return dependencies;
    22. }
    23.  
    24. static TypeDB GetTypeDB(BuildTarget buildTarget)
    25. {
    26.     BuildTargetGroup group;
    27.     if (!Enum<BuildTargetGroup>.TryParse(buildTarget.ToString(), out group))
    28.         group = BuildTargetGroup.Standalone;
    29.  
    30.     var settings = new ScriptCompilationSettings
    31.     {
    32.         target = buildTarget,
    33.         group = group,
    34.         options = ScriptCompilationOptions.None,
    35.     };
    36.  
    37.     var tempPath = ".temp/AssetBundleHelper_Compile";
    38.     if (Directory.Exists(tempPath))
    39.         Directory.Delete(tempPath, true);
    40.     var results = PlayerBuildInterface.CompilePlayerScripts(settings, tempPath);
    41.  
    42.     var typeDB = results.typeDB;
    43.     return typeDB;
    44. }
    Note: GetTypeDB must be cached as it executes a compilation step for the standalone libraries which takes some time.
     
    SugoiDev and fherbst like this.
  3. LeonhardP

    LeonhardP

    Unity Technologies

    Joined:
    Jul 4, 2016
    Posts:
    3,136
  4. fherbst

    fherbst

    Joined:
    Jun 24, 2012
    Posts:
    802
  5. LeonhardP

    LeonhardP

    Unity Technologies

    Joined:
    Jul 4, 2016
    Posts:
    3,136
  6. Prodigga

    Prodigga

    Joined:
    Apr 13, 2011
    Posts:
    1,123
    At least there is a temporary work around and it is confirmed as fixed :)