Using Unity 2019.2.13f1
How to exactly use Addressables.CheckForCatalogUpdates()?
Here’s how I did it:
void Start()
{
var aw = Addressables.CheckForCatalogUpdates(false);
aw.Completed += OnCompletedCheck;
}
private void OnCompletedCheck(AsyncOperationHandle<List<string>> obj)
{
var catalogList = obj.Result;
Debug.Log("CATALOG COUNT - " + catalogList.Count);
}
I run this every time I update a previous build, and uploading the updated bundle and catalog. The problem is, the count always return 0, meaning there are no updatable catalog.
Reading the documentation, what I understood that this works with static contents, so I also tried building a group with static contents, then changed some of it, checked for update restriction then applied. It still returns 0.
Although the assets are updated with the remote asset when running the app, the problem is I don’t know if I should prompt a update or prompt a download for the asset. I know how to check if an asset is already cached or needs to be downloaded, but not how to check if the asset is cached, but there is a new update.
UPDATE:
It seems that using Addressables.ClearDependencyCacheAsync(key) can clear the cached asset, so I used it like this:
void Start()
{
Addressables.GetDownloadSizeAsync(key).Completed += GetSizeDone;
}
void GetSizeDone(AsyncOperationHandle<long> obj)
{
long fileSize = obj.Result;
if (fileSize == 0)
//Asset is cached and no update
else
{
//Asset is new or cached asset has update, can't say. So I need to clear the old cache first
Addressables.ClearDependencyCacheAsync(obj);
Addressables.ClearDependencyCacheAsync(key);
// used the handle and the asset name just to be sure
}
Addressables.Release(obj);
}
I was expecting that the even before I download the new update/asset, the old cached asset has already been cleared, but when I checked the size, it didn’t decreased at all.
This means that Addressables.ClearDependencyCacheAsync(key) only clears whatever the current catalog’ assets points to, like if you download the new/updated asset, then call the method, it will be cleared. But if it checks that there is a new asset/update and called the method, the old asset will not be cleared