Search Unity

Bug addressables@1.16.16 uses obsolete AssetDatabaseExperimental methods with Unity 2020.2+

Discussion in 'Addressables' started by Midiphony, Feb 4, 2021.

  1. Midiphony

    Midiphony

    Joined:
    Jan 25, 2019
    Posts:
    14
    Hello !

    When using the latest verified Addressables package with Unity 2020.2.3, I am getting the following errors :
    On my project, the use of obsolete methods prevent compilation...

    This is the problematic code inside BuildScriptVirtualMode.cs :
    Code (CSharp):
    1. static string OutputLibraryPathForAsset(string a)
    2.         {
    3.             var guid = AssetDatabase.AssetPathToGUID(a);
    4.             var legacyPath = string.Format("Library/metadata/{0}{1}/{2}", guid[0], guid[1], guid);
    5. #if UNITY_2020_2_OR_NEWER
    6.             var hash = Experimental.AssetDatabaseExperimental.GetArtifactHash(guid); // /!\ /!\/!\ obsolete
    7.             if (Experimental.AssetDatabaseExperimental.GetArtifactPaths(hash, out var paths)) // /!\ /!\/!\ obsolete
    8.                 return Path.GetFullPath(paths[0]);
    9.             else
    10.                 legacyPath = String.Empty; // legacy path is never valid in 2020.2+
    11. #elif UNITY_2019_3_OR_NEWER
    12.             if (IsAssetDatabaseV2Enabled()) // AssetDatabase V2 is optional in 2019.3 and 2019.4
    13.             {
    14.                 var hash = Experimental.AssetDatabaseExperimental.GetArtifactHash(guid);
    15.                 if (Experimental.AssetDatabaseExperimental.GetArtifactPaths(hash, out var paths))
    16.                     return Path.GetFullPath(paths[0]);
    17.             }
    18. #endif
    19.             return legacyPath;
    20.         }
    What would you propose ?

    Thanks
     
  2. TreyK-47

    TreyK-47

    Unity Technologies

    Joined:
    Oct 22, 2019
    Posts:
    1,820
    I'll shoot this over to the team for some input!
     
  3. PigletPants

    PigletPants

    Joined:
    Sep 19, 2019
    Posts:
    23
    Same problem here after the upgrade.
     
  4. Midiphony-panda

    Midiphony-panda

    Joined:
    Feb 10, 2020
    Posts:
    243
    I don't have the issue when I use version 1.17.4-preview, if it helps.

    But it's a preview version : while 1.17 isn't verified, it would be nice to have a fix on the verified version (1.16) :)
     
  5. davidla_unity

    davidla_unity

    Unity Technologies

    Joined:
    Nov 17, 2016
    Posts:
    763
    Like @Midiphony-panda said, I think this is fixed in 1.17-preview. I understand if you don't want to update to a preview version of the package. We'll likely come out of preview in the next few weeks though I'm not sure exactly when.

    The quickest workaround I can think to suggest if you don't want to update versions yet is to move the package from the Library/PackageCache folder and put it into the projects Packages directly so you can edit it. The new code for that method is:

    Code (CSharp):
    1.  
    2. static string OutputLibraryPathForAsset(string a)
    3.         {
    4.             var guid = AssetDatabase.AssetPathToGUID(a);
    5.             var legacyPath = string.Format("Library/metadata/{0}{1}/{2}", guid[0], guid[1], guid);
    6. #if UNITY_2020_2_OR_NEWER          
    7.             var artifactID = Experimental.AssetDatabaseExperimental.ProduceArtifact(new ArtifactKey(new GUID(guid)));
    8.             if (Experimental.AssetDatabaseExperimental.GetArtifactPaths(artifactID, out var paths))
    9.                 return Path.GetFullPath(paths[0]);
    10.             else
    11.                 legacyPath = String.Empty;
    12. #elif UNITY_2020_1_OR_NEWER
    13.             var hash = Experimental.AssetDatabaseExperimental.GetArtifactHash(guid);
    14.             if (Experimental.AssetDatabaseExperimental.GetArtifactPaths(hash, out var paths))
    15.                 return Path.GetFullPath(paths[0]);
    16.             else
    17.                 legacyPath = String.Empty; // legacy path is never valid in 2020.1+
    18. #elif UNITY_2019_3_OR_NEWER
    19.             if (IsAssetDatabaseV2Enabled()) // AssetDatabase V2 is optional in 2019.3 and 2019.4
    20.             {
    21.                 var hash = Experimental.AssetDatabaseExperimental.GetArtifactHash(guid);
    22.                 if (Experimental.AssetDatabaseExperimental.GetArtifactPaths(hash, out var paths))
    23.                     return Path.GetFullPath(paths[0]);
    24.             }
    25. #endif
    26.             return legacyPath;
    27.         }
    28.  
    Hopefully that helps!