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. Dismiss Notice

LoadContentCatalogAsync adds hash file in cache directory as dependency and fails if missing

Discussion in 'Addressables' started by VSSW-GTN, Aug 26, 2020.

  1. VSSW-GTN

    VSSW-GTN

    Joined:
    Feb 24, 2020
    Posts:
    4
    As we are building a slim frontend client for visualization which is downloading needed assets at runtime from customer defined servers, Addressables are the perfect fit for our needs.

    We are currently trying to load a catalog built in another project with LoadContentCatalogAsync on request from a webserver serving the *.json, *.hash and *.bundle files. Every time the addressables system tries to load the catalog, it also adds the (probably) cached version of the hash as dependency in a local runtime directory which in my case is
    C:\Users\user\AppData\LocalLow\ProductName\com.unity.addressables\CatalogName.hash


    Loading this cached version was never requested and should not be a reason for failure.
    Because this file does not exist yet, the dependent download of the hash & json files fail. As the downloads fail, the locally cached *.hash file never gets created. This is an endless cycle and I do not know if this is by design or whether we are doing something wrong.

    upload_2020-8-26_17-10-41.png

     
    Last edited: Aug 27, 2020
    Mese96 likes this.
  2. ProtoTerminator

    ProtoTerminator

    Joined:
    Nov 19, 2013
    Posts:
    566
    You need to prepend your path with the
    file://
    protocol for local file access.
     
  3. VSSW-GTN

    VSSW-GTN

    Joined:
    Feb 24, 2020
    Posts:
    4
    As I said, the original request was to http://localhost:8091/base/catalog-latest.json. The Addressables system added the local file as dependency automatically, the same way it added the *.hash file as dependency. This was not set by us. The question is, why this locally cached file gets added as mandatory dependency and how we can prevent that or make it optional, as this prevents the download from ever succeeding. There can be no local cache of a file the addressables system hasn't even downloaded once when that download fails because of the missing local cache...

    Code (CSharp):
    1.  
    2.         internal ResourceLocationBase CreateCatalogLocationWithHashDependencies(string catalogPath, string hashFilePath)
    3.         {
    4.             var catalogLoc = new ResourceLocationBase(catalogPath, catalogPath, typeof(ContentCatalogProvider).FullName, typeof(IResourceLocator));
    5.  
    6.             if (!string.IsNullOrEmpty(hashFilePath))
    7.             {
    8.                 string cacheHashFilePath = ResolveInternalId(kCacheDataFolder + Path.GetFileName(hashFilePath));
    9.  
    10.                 catalogLoc.Dependencies.Add(new ResourceLocationBase(hashFilePath, hashFilePath, typeof(TextDataProvider).FullName, typeof(string)));
    11.                 catalogLoc.Dependencies.Add(new ResourceLocationBase(cacheHashFilePath, cacheHashFilePath, typeof(TextDataProvider).FullName, typeof(string)));
    12.             }
    13.  
    14.             return catalogLoc;
    15.         }
    16.  
    this is the code responsible for adding the cache dependency in AddressablesImpl.cs called from LoadContentCatalogAsync() and we don't have any way of telling it to ignore the cache if the cached file does not yet exist.
     
    Last edited: Aug 27, 2020
  4. Mese96

    Mese96

    Joined:
    Jul 23, 2013
    Posts:
    40
    I have the same problem, albeit I am only loading a catalog locally. In this use case I never need a cached version, it is anyway on the same disk. Is there any way to disable the caching completly ?
    It works when line 11 from the previous example is commented out, but I would prefer not to edit unity packages.
     
  5. VSSW-GTN

    VSSW-GTN

    Joined:
    Feb 24, 2020
    Posts:
    4
    Our workaround was to create an empty cache file for now if it does not exist before sending the load catalog request.
     
  6. Mese96

    Mese96

    Joined:
    Jul 23, 2013
    Posts:
    40
    Not the most sane solution, but it works, thanks for the idea.
     
  7. VSSW-GTN

    VSSW-GTN

    Joined:
    Feb 24, 2020
    Posts:
    4
    Until this is fixed in the package (or someone tells us how it should be used) there is no other way I could think of.
     
    Mese96 likes this.
  8. drallcom3

    drallcom3

    Joined:
    Feb 12, 2017
    Posts:
    162
    How do I create an empty cache file? I get this exact same error (and I'm not the best at using addressables). Any hint would be highly appreciated.

    Is it really as silly as
    Code (CSharp):
    1. CreateDirectory("com.unity.addressables")
    2. File.WriteAllText("path/name.hash", "")
    ?
    Because it works with that hack.
     
    Last edited: Oct 9, 2020
  9. Przemyslaw_Zaworski

    Przemyslaw_Zaworski

    Joined:
    Jun 9, 2017
    Posts:
    314
    I have a similar problem.I want to use Addressable System as part of modding tool, where user can load bundles generated from another projects.

    For example I have a local directory E:\Mods\ with three files:

    upload_2020-11-2_10-51-14.png
    I can load prefab with following test script:
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using System.Threading.Tasks;
    5. using UnityEngine.AddressableAssets;
    6. using UnityEngine.AddressableAssets.ResourceLocators;
    7. using UnityEngine.ResourceManagement.AsyncOperations;
    8.  
    9. public class AddressableTest : MonoBehaviour
    10. {
    11.     async Task<IResourceLocator> LoadConfig (string filepath)
    12.     {
    13.         AsyncOperationHandle<IResourceLocator> locator = Addressables.LoadContentCatalogAsync(filepath);
    14.         await locator.Task;
    15.         return locator.Result;    
    16.     }
    17.  
    18.     async Task<GameObject> LoadAssetInstance(string address)
    19.     {
    20.         AsyncOperationHandle<GameObject> handle = Addressables.LoadAssetAsync<GameObject>(address);
    21.         await handle.Task;
    22.         return Instantiate(handle.Result);
    23.     }
    24.  
    25.     async void LoadMod()
    26.     {
    27.         IResourceLocator locator = await LoadConfig ("E:/Mods/catalog.json");
    28.         GameObject instance = await LoadAssetInstance("Assets/Prefabs/Cube.prefab");
    29.     }
    30.  
    31.     void Start()
    32.     {
    33.         Addressables.Initialize();
    34.     }
    35.  
    36.     async void Update()
    37.     {
    38.         if (Input.GetKeyDown(KeyCode.Space))
    39.         {
    40.             LoadMod();
    41.         }
    42.     }
    43. }
    Catalog.json content (with proper paths to bundle files):

    Code (CSharp):
    1. {
    2.     "m_LocatorId": "AddressablesMainContentCatalog",
    3.     "m_InstanceProviderData": {
    4.         "m_Id": "UnityEngine.ResourceManagement.ResourceProviders.InstanceProvider",
    5.         "m_ObjectType": {
    6.             "m_AssemblyName": "Unity.ResourceManager, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null",
    7.             "m_ClassName": "UnityEngine.ResourceManagement.ResourceProviders.InstanceProvider"
    8.         },
    9.         "m_Data": ""
    10.     },
    11.     "m_SceneProviderData": {
    12.         "m_Id": "UnityEngine.ResourceManagement.ResourceProviders.SceneProvider",
    13.         "m_ObjectType": {
    14.             "m_AssemblyName": "Unity.ResourceManager, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null",
    15.             "m_ClassName": "UnityEngine.ResourceManagement.ResourceProviders.SceneProvider"
    16.         },
    17.         "m_Data": ""
    18.     },
    19.     "m_ResourceProviderData": [
    20.         {
    21.             "m_Id": "UnityEngine.ResourceManagement.ResourceProviders.AssetBundleProvider",
    22.             "m_ObjectType": {
    23.                 "m_AssemblyName": "Unity.ResourceManager, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null",
    24.                 "m_ClassName": "UnityEngine.ResourceManagement.ResourceProviders.AssetBundleProvider"
    25.             },
    26.             "m_Data": ""
    27.         },
    28.         {
    29.             "m_Id": "UnityEngine.ResourceManagement.ResourceProviders.BundledAssetProvider",
    30.             "m_ObjectType": {
    31.                 "m_AssemblyName": "Unity.ResourceManager, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null",
    32.                 "m_ClassName": "UnityEngine.ResourceManagement.ResourceProviders.BundledAssetProvider"
    33.             },
    34.             "m_Data": ""
    35.         },
    36.         {
    37.             "m_Id": "UnityEngine.ResourceManagement.ResourceProviders.BundledAssetProvider",
    38.             "m_ObjectType": {
    39.                 "m_AssemblyName": "Unity.ResourceManager, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null",
    40.                 "m_ClassName": "UnityEngine.ResourceManagement.ResourceProviders.BundledAssetProvider"
    41.             },
    42.             "m_Data": ""
    43.         }
    44.     ],
    45.     "m_ProviderIds": [
    46.         "UnityEngine.ResourceManagement.ResourceProviders.AssetBundleProvider",
    47.         "UnityEngine.ResourceManagement.ResourceProviders.BundledAssetProvider"
    48.     ],
    49.     "m_InternalIds": [
    50.         "E:/Mods/defaultlocalgroup_assets_all_42dbec10207f246e82c3dd5be1bd89f2.bundle",
    51.         "E:/Mods/defaultlocalgroup_unitybuiltinshaders_39344c31bed943233cbf6c80270fdee4.bundle",
    52.         "Assets/Prefabs/Cube.prefab"
    53.     ],
    54.     "m_KeyDataString": "BQAAAABEAAAAZGVmYXVsdGxvY2FsZ3JvdXBfYXNzZXRzX2FsbF80MmRiZWMxMDIwN2YyNDZlODJjM2RkNWJlMWJkODlmMi5idW5kbGUATQAAAGRlZmF1bHRsb2NhbGdyb3VwX3VuaXR5YnVpbHRpbnNoYWRlcnNfMzkzNDRjMzFiZWQ5NDMyMzNjYmY2YzgwMjcwZmRlZTQuYnVuZGxlABoAAABBc3NldHMvUHJlZmFicy9DdWJlLnByZWZhYgAgAAAAYjYzOGZjOGI4ZTgwZWNjNGY5NGZhZGIyNzZlNzg1OTEEzHByXg==",
    55.     "m_BucketDataString": "BQAAAAQAAAABAAAAAAAAAE0AAAABAAAAAQAAAJ8AAAABAAAAAgAAAL4AAAABAAAAAgAAAOMAAAACAAAAAAAAAAEAAAA=",
    56.     "m_EntryDataString": "AwAAAAAAAAAAAAAA/////wAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAP////8AAAAAgwIAAAEAAAAAAAAAAgAAAAEAAAAEAAAAzHByXv////8CAAAAAQAAAA==",
    57.     "m_ExtraDataString": "B0xVbml0eS5SZXNvdXJjZU1hbmFnZXIsIFZlcnNpb249MC4wLjAuMCwgQ3VsdHVyZT1uZXV0cmFsLCBQdWJsaWNLZXlUb2tlbj1udWxsSlVuaXR5RW5naW5lLlJlc291cmNlTWFuYWdlbWVudC5SZXNvdXJjZVByb3ZpZGVycy5Bc3NldEJ1bmRsZVJlcXVlc3RPcHRpb25z5gEAAHsAIgBtAF8ASABhAHMAaAAiADoAIgA0ADIAZABiAGUAYwAxADAAMgAwADcAZgAyADQANgBlADgAMgBjADMAZABkADUAYgBlADEAYgBkADgAOQBmADIAIgAsACIAbQBfAEMAcgBjACIAOgA0ADEAMwA1ADAANAAxADQAMQAsACIAbQBfAFQAaQBtAGUAbwB1AHQAIgA6ADAALAAiAG0AXwBDAGgAdQBuAGsAZQBkAFQAcgBhAG4AcwBmAGUAcgAiADoAZgBhAGwAcwBlACwAIgBtAF8AUgBlAGQAaQByAGUAYwB0AEwAaQBtAGkAdAAiADoALQAxACwAIgBtAF8AU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IAbQBfAEIAdQBuAGQAbABlAFMAaQB6AGUAIgA6ADMAOAA2ADgANgAsACIAbQBfAFUAcwBlAEMAcgBjAEYAbwByAEMAYQBjAGgAZQBkAEIAdQBuAGQAbABlAHMAIgA6AHQAcgB1AGUAfQA=",
    58.     "m_Keys": [
    59.         "defaultlocalgroup_assets_all_42dbec10207f246e82c3dd5be1bd89f2.bundle",
    60.         "defaultlocalgroup_unitybuiltinshaders_39344c31bed943233cbf6c80270fdee4.bundle",
    61.         "Assets/Prefabs/Cube.prefab",
    62.         "b638fc8b8e80ecc4f94fadb276e78591",
    63.         "1584558284"
    64.     ],
    65.     "m_resourceTypes": [
    66.         {
    67.             "m_AssemblyName": "Unity.ResourceManager, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null",
    68.             "m_ClassName": "UnityEngine.ResourceManagement.ResourceProviders.IAssetBundleResource"
    69.         },
    70.         {
    71.             "m_AssemblyName": "UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null",
    72.             "m_ClassName": "UnityEngine.GameObject"
    73.         }
    74.     ]
    75. }
    and indeed, object (Cube) can be spawned properly, but additionally it casts a bunch of errors:

    upload_2020-11-2_10-54-25.png

    like this:
    "Exception encountered in operation Resource<Object>(catalog.hash), status=Failed, result= : Invalid path in TextDataProvider : 'E:/Mods/catalog.hash'."

    Why object is loaded properly and errors are thrown ?

    I edited code from AddressablesImp.cs:

    Code (CSharp):
    1.         internal ResourceLocationBase CreateCatalogLocationWithHashDependencies(string catalogPath, string hashFilePath)
    2.         {
    3.             var catalogLoc = new ResourceLocationBase(catalogPath, catalogPath, typeof(ContentCatalogProvider).FullName, typeof(IResourceLocator));
    4.  
    5.             if (!string.IsNullOrEmpty(hashFilePath))
    6.             {
    7.                 string cacheHashFilePath = ResolveInternalId(kCacheDataFolder + Path.GetFileName(hashFilePath));
    8.  
    9.                 //catalogLoc.Dependencies.Add(new ResourceLocationBase(hashFilePath, hashFilePath, typeof(TextDataProvider).FullName, typeof(string)));
    10.                 //catalogLoc.Dependencies.Add(new ResourceLocationBase(cacheHashFilePath, cacheHashFilePath, typeof(TextDataProvider).FullName, typeof(string)));
    11.             }
    12.  
    13.             return catalogLoc;
    14.         }
    but errors are thrown still. When I include empty catalog.hash, error disappears, but prefab is not loaded.
     
    Last edited: Nov 2, 2020
  10. Przemyslaw_Zaworski

    Przemyslaw_Zaworski

    Joined:
    Jun 9, 2017
    Posts:
    314
    I found a solution.
    In destination project, I moved ProjectName\Library\PackageCache\com.unity.addressables@1.16.1 into ProjectName\Packages, and restarted Editor. Now, with edited CreateCatalogLocationWithHashDependencies function, everything is fine.
     
  11. retrobrain_dongyi_cai

    retrobrain_dongyi_cai

    Joined:
    Feb 3, 2021
    Posts:
    10
    Bump, I have the same question.

    How is the hash file should look like??? I can't find it anywhere!