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

Cannot use cached addressables at all

Discussion in 'Addressables' started by thexdd, Aug 9, 2021.

  1. thexdd

    thexdd

    Joined:
    Mar 20, 2013
    Posts:
    18
    Addressables package version: 1.18.15

    I have been trying to implement any workable solution for this but I just can't. This is absolutely ridiculous.
    Following this guy post I implemented the PlayFab Addressables system. Basically it allows us to use signed URL's with addressables system (which by itself turned out to be not that intuitive to implement but anyway).
    So the system works by using 3 IResourceProvider implementations:
    • Hash provider
    • Json provider
    • AssetBundle provider

    Here's an example of one of those asset providers,
    Code (CSharp):
    1. public class PlayFabJsonAssetProvider : JsonAssetProvider
    2. {
    3.     public override string ProviderId => typeof(JsonAssetProvider).FullName;
    4.  
    5.     public PlayFabJsonAssetProvider(PlayFabApiController playFabApi)
    6.     {
    7.         _playFabApi = playFabApi;
    8.     }
    9.  
    10.     public override async void Provide(ProvideHandle provideHandle)
    11.     {
    12.         if (provideHandle.Location.InternalId.StartsWith("playfab://") == false)
    13.         {
    14.             base.Provide(provideHandle);
    15.             return;
    16.         }
    17.  
    18.         var internalId = provideHandle.Location.InternalId.Replace("playfab://", "");
    19.         Assert.IsTrue(provideHandle.Location.ResourceType == typeof(ContentCatalogData), "Only catalogs supported");
    20.         var url = await _playFabApi.GetContentDownloadUrlAsync(internalId);
    21.         var resourceLocation = new ResourceLocationBase(internalId, url, typeof(JsonAssetProvider).FullName, typeof(string));
    22.         var handle = provideHandle.ResourceManager.ProvideResource<ContentCatalogData>(resourceLocation);
    23.         provideHandle.Complete(await handle.Task, true, handle.OperationException);
    24.     }
    25. }
    In principle, they are the same meaning that all of those providers use
    ResourceManager.ProvideResource method. Where each of the provider performs an external web request to get the signed URL and then creates an implementation of the
    IResourceLocation interface with the url passed as the InternalId.

    And it works just fine. THE PROBLEM happens when I am trying to load the assets in offline mode. When the game is not connected to the internet.

    Obviously, the providers are still trying to obtain the signed URLs but they are unable to. So I decided to cache those URLs. But that didn't work. Here is what happens when I am trying to use cached URLs:

    RemoteProviderException : TextDataProvider : unable to load from url : https://pf-content-live.s3.us-west-2.amazonaws...


    But why is it trying to load anything from this url? Isn't it supposed to load it from the local cache? Do I miss something? Its drivin me nuts now. I am wasting so much time on this. Any help would be highly appreciated, thanks.
     
    Last edited: Sep 14, 2021
  2. TreyK-47

    TreyK-47

    Unity Technologies

    Joined:
    Oct 22, 2019
    Posts:
    1,795
    I'll flag with the team for some guidance.
     
    thexdd likes this.
  3. unity_krista

    unity_krista

    Unity Technologies

    Joined:
    Apr 28, 2020
    Posts:
    40
    Addressables auto caches AssetBundles and catalogs, but we had to write our own caching for the AssetBundles. To do something custom like you have, you'll probably have to cache data and check the cache on your own as well. You could use TransformInternalId or something similar to transform urls into local paths and then do a cache check before using the url. See https://docs.unity3d.com/Packages/com.unity.addressables@1.14/manual/TransformInternalId.html

    Also, UnityWebRequest automatically caches too, but it's because it's built into the engine that way, and it requires giving a hash along with the URI. See https://docs.unity3d.com/ScriptReference/Networking.UnityWebRequestAssetBundle.GetAssetBundle.html

    To my knowledge, those are the only situations that things get automatically cached related to AssetBundles
     
  4. thexdd

    thexdd

    Joined:
    Mar 20, 2013
    Posts:
    18
    Thank you for trying to help, Krista. Unfortunately I have decided to reject this whole custom provider idea, since the given feature is very poorly designed by the Addressable's developers, in my humble opinion.

    Main reasons why I decided to use "default" providers would be that I couldn't find an adequate enough documentation for my custom providers implementation.

    I literally do not understand why it has to be so complex. The addressables' developers are saying they let me build whatever I need, it's flexible. Yet, it is not flexible but rather extremely sophisticated. Oh, and there is also a ton of bugs.

    Anyway, during my attempts I've stuck on not being able to cache the catalog, hash and the assetbundle links.
    It just wouldn't work. Perhaps one day this will change, or maybe it's even possible right now. I don't know.

    Have a good day.
     
  5. ImpossibleRobert

    ImpossibleRobert

    Joined:
    Oct 10, 2013
    Posts:
    511
    I am struggling with the default provider as well. The system behaves just so erratically which is really frustrating and I am starting to get 1 star ratings since the game cannot be played offline on Android. In the editor, without internet all works as expected.

    On Android (Oculus Quest, Wifi disabled), it for some reason tries to download the catalog again, fails and will not provide a locally cached version of the catalog. Is that a known bug? @unity_krista @TreyK-47 ?

    Code (CSharp):
    1.  
    2. 2021.12.30 22:17:47.241 27119 27140 Warn Unity Unable to load ContentCatalogData from location [URL]https://travrsal-live.sfo2.cdn.digitaloceanspaces.com/Worlds/Pyramid/Android/catalog.json[/URL]. Attempting to retry...
    3. 2021.12.30 22:17:47.241 27119 27140 Warn Unity UnityEngine.AddressableAssets.ResourceProviders.InternalOp:OnCatalogLoaded(ContentCatalogData)
    4. 2021.12.30 22:17:47.241 27119 27140 Warn Unity UnityEngine.AddressableAssets.ResourceProviders.InternalOp:CatalogLoadOpCompleteCallback(AsyncOperationHandle`1)
    5. 2021.12.30 22:17:47.241 27119 27140 Warn Unity System.Action`1:Invoke(T)
    6. 2021.12.30 22:17:47.241 27119 27140 Warn Unity DelegateList`1:Invoke(T)
    7. 2021.12.30 22:17:47.241 27119 27140 Warn Unity UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationBase`1:InvokeCompletionEvent()
    8. 2021.12.30 22:17:47.241 27119 27140 Warn Unity UnityEngine.ResourceManagement.ResourceManager:ExecuteDeferredCallbacks()
    9. 2021.12.30 22:17:47.241 27119 27140 Warn Unity UnityEngine.ResourceManagement.ResourceManager:Update(Single)
    10. 2021.12.30 22:17:47.241 27119 27140 Warn Unity System.Action`1:Invoke(T)
    11.  
    Interestingly enough, while on PC there is a folder "com.unity.addressables" created containing all the cached hashes, on Quest this does not seem to exist or is hidden in a different location. Might that hint to an issue? There is a "UnityCache/Shared" folder containing all the downloaded bundles, but no catalogs or hashes anywhere.
     
    Last edited: Dec 30, 2021