How to check if an addressable asset has been downloaded already?

There are some UI elements that display depending on if there is something to download or not.

Using Addressables.GetDownloadSizeAsync might work, but I’m looking for an alternative

Bump, I’d also like to know this.

@faolad , does GetDownloadSizeAsync work?

Docstring of GetDownloadSizeAsync:
/// Determines the required download size, dependencies included, for the specified .
/// Cached assets require no download and thus their download size will be 0. The Result of the operation
/// is the download size in bytes.

If you check the implementation of the API, it collects all dependencies of the address, then go through each
IResourceLocation, and do the math. It sounds a right way to go.

2 Likes

GetDownloadSizeAsync seems like the way to go, but at the moment it doesn’t work. It always returns 0.

What situation are you in? Windows stand alone builds? Play mode? some other platform?
If it’s always returning 0 that doesn’t seem very helpful, so we’d like to figure out what’s going on there.

It happens on Windows Stand-alone Build, IOS and in Play Mode. We only have tested on those platforms.

There was a bug related to this that we recently fixed. Please ensure you have new, never before downloaded content, (or turn off bundle caching in your group settings) and try this again with 1.1.7.
If it’s still giving you 0, we’d love to know.

2 Likes

Still giving 0. I ensure everything its new, never before downloaded content.

Well, two ways we could proceed…

  1. you make a Unity bug report with a repro project and we try to get to the bottom of it.
  2. you put some breakpoints and/or debug logging in our code and let us know where it’s getting lost.

If you choose 2, the place to look is ComputeSize inside AssetBundleProvider.cs. Most likely adding a log at the start would be enough to point us in the right direction

        public virtual long ComputeSize(IResourceLocation loc)
        {
            Debug.Log("CompSize: " + loc.InternalId + ", " + BundleSize);
            if (!loc.InternalId.Contains("://"))
                return 0;
  • If InternalId has"://" and BundleSize > 0, then the step would be to use logs or breakpoints to work out why it’s returning 0.
  • If BundleSize == 0, then you need to look for “BundleSize = GetFileSize(info.FileName)” inside BuildScriptPackedMode.cs and work out why it’s 0
  • If InternalId doesn’t have “://” then I don’t know how it’ll download anyway.
1 Like

Just clarify that GetDownloadSizeAsync returns the bundle size required to download (haven’t downloaded yet). And once the bundle get downloaded, it will returns 0 (nothing need to download).

If it always 0, then

  1. The bundle may be downloaded already. Try Caching.ClearCache(); before any AAS code, to clean the cache.
  2. The bundle is a local one. Check Library/com.unity.addressables/StreamingAssetsCopy/aa/Windows/catalog.json search your bundle name, see if it starts with http.

If still not work, you may want to debug the AddressableImpl.GetDownloadSizeAsync, see what happens internally.

3 Likes

Try change Play Mode Script to “Simulate Groups (Advanced)” it works for me
My Addressable version is 1.3.3

5144783--509360--upload_2019-11-6_19-50-42.png

1 Like

Bump this question now. In Addressables 1.11.2, GetDownloadSizeAsync always returns the actual file size of the bundle, so this method doesn’t work now.

Edit:
Yeah, I am pretty sure things have changed in Addressables 1.11.2. I still can find the sentence Cached assets require no download and thus their download size will be 0. in the doc of the Addressables 1.10.0. But the doc of Addressables 1.11.2 isn’t out yet. And I have tested Addressables 1.10.0, the GetDownloadSizeAsync method did return zero if the bundle has been downloaded. However, in Addressables 1.11.2, they seem to have change the way GetDownloadSizeAsync works, now it always returns the actual file size no matter what.

2 Likes

Yeah I’ve noticed this behaviour after upgrading to1.11.2. The 1.11.2 documentation still has the line: “Cached assets require no download and thus their download size will be 0.”

Is this a bug with the latest version or has the documentation not been updated? Can someone from Unity let us know what the correct way to tell if a remote asset is cached?

1 Like

Same here. I can confirm that 1.11.2 has changed the behavior of GetDownloadSizeAsync() so that it now always returns the size no matter if the data is cached or not.
The documentation for 1.11.2 is out now and it says all the same: “Cached assets require no download and thus their download size will be 0.” (Class Addressables | Addressables | 1.11.2).

1 Like

Just wanted to confirm our team is in the same boat here. And having to comply with Apple’s requirement of “show an approval dialog to download assets” is going to show every time now even if things are cached. Would love a hotfix for this if possible.

Addressables 1.13.1 is out and it’s changelog says “Fixed bug where GetDownloadSizeAsync was returning non-zero values for cached AssetBundles.”.
Have anyone tested it already?

I did. It’s fixed.

2 Likes

Noted that in 1.13.1 the GetDownloadSizeAsync works fine.
But in my app i’m having a storage management feature. And since Addressable.ClearDependancy is useless i’m using Directory.Delete with path and bundle name from Addressable.
The solution work fine since it only delete what I want to delete but it seem conflict with the GetDownloadeSizeAsync that the function will return non-zero bundle size for bundle that has been downloaded and I checked that only 1 bundle delete from cache.

TLDR: GetDownloadSizeSync work fine until you use Directory.Delete to remove bundle from cache (Addressable 1.13.1)

2 Likes

@unity_bill Addressables 1.16.10 GetDownloadSizeAsync for bundle returns 0, but for asset inside bundle result is non 0, any suggestions? as far as I understand this isn’t expected behavior