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,
public class PlayFabJsonAssetProvider : JsonAssetProvider
{
public override string ProviderId => typeof(JsonAssetProvider).FullName;
public PlayFabJsonAssetProvider(PlayFabApiController playFabApi)
{
_playFabApi = playFabApi;
}
public override async void Provide(ProvideHandle provideHandle)
{
if (provideHandle.Location.InternalId.StartsWith("playfab://") == false)
{
base.Provide(provideHandle);
return;
}
var internalId = provideHandle.Location.InternalId.Replace("playfab://", "");
Assert.IsTrue(provideHandle.Location.ResourceType == typeof(ContentCatalogData), "Only catalogs supported");
var url = await _playFabApi.GetContentDownloadUrlAsync(internalId);
var resourceLocation = new ResourceLocationBase(internalId, url, typeof(JsonAssetProvider).FullName, typeof(string));
var handle = provideHandle.ResourceManager.ProvideResource<ContentCatalogData>(resourceLocation);
provideHandle.Complete(await handle.Task, true, handle.OperationException);
}
}
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.
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 TransformInternalId | Addressables | 1.14.3
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.
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 ?
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.