Addressables: PercentComplete 0 during asset download
Asked Answered
H

3

0

Hey everyone. Maybe someone can help me out here in understanding the gap in my knowledge. I’m having an issue getting the Addressbles to correctly show their download progress.
Below you’ll see two screenshots attached. The gray one is my console output, the multicolored one is a standalone build output.

My addresables are hosted in DigitalOcean and are not local to my machine.
The size of my packed assets bundle is 10megs and change. When I iterate over each item in my pack I get its the size and then proceed to download it.

EDIT
So I’ve figured out 3 of my 4 issues, the final issue seems to be a bug with Unity possibly? I still cannot figure out why the percent complete does not increase. Does the percent complete only apply to the loading of an asset and does it not take into account downloading progress?

1st Issue: It seems GetDownloadSizeAsync(key) gets the bundles entire file size, and not the size of the asset which was entered for the key in editor.

Solution: When creating a ‘packed’ assets, the entire asset size is queried regardless of key. To remedy this, each asset needs to be its own pack OR the packets bundle mode needs to be set to pack separately.

2nd Issue: GetDownloadSizeAsync(key) never returns a value for the standalone build.

Solution:
This is intended design.

3rd Issue: Progress is always 0 until near the end. (I calculate bytes downloaded as progress*total)

4th Issue: For all assets, after the first key downloaded asset the remainder have an interesting percentage pattern, and now the total bytes for that key always returns 0.

Solution:
When accessing a single asset in a packed asset bundle with the mode set to pack together, the entire bundle is downloaded to access that one asset. This means the remainder of items are downloaded and it is loading them.

Code:

public async Task<LoadedAssetList> LoadAssets(List<string> assetsToLoad)
{
    LoadedAssetList _loadedAssetList = new LoadedAssetList();
    _maximumPercentageAmount = assetsToLoad.Count;
    foreach (string item in assetsToLoad)
    {
        _loadedAssetList.AddAsset(item, await AddressablesUtil.WaitForAssetToLoad(item, _UpdateLoadedPercentageTotal));
    }
    
    return _loadedAssetList;
}


public class AddressablesUtil
{
    public static async Task<GameObject> WaitForAssetToLoad(string key, Action<double, long, string> percentageCompleteCallback = null)
    {
        AsyncOperationHandle<long> sizeHandle = Addressables.GetDownloadSizeAsync(key);

        await new WaitUntil(() => sizeHandle.IsDone);

        long b = sizeHandle.Result;
        AsyncOperationHandle<GameObject> loadAssetHandle = Addressables.LoadAssetAsync<GameObject>(key);
        while (loadAssetHandle.IsDone != true)
        {
            percentageCompleteCallback?.Invoke(loadAssetHandle.PercentComplete * sizeHandle.Result, sizeHandle.Result, key);
            await new WaitForEndOfFrame();
        }

        return loadAssetHandle.Result;
    }
}

I assume I’m missing something important about how this is supposed to work but I’m at a loss and I’ve been working on this all day.

Console output & addressables packer

Standalone build download logs

Hartfield answered 12/12, 2023 at 16:59 Comment(0)
B
0

Hi spanagiotis,
Did you manage to solve the issue #3?

Bunn answered 17/2, 2020 at 19:3 Comment(1)

BTW, there is more info on this issue here: https://forum.unity.com/threads/0-7-4-addressables-downloaddependencies-percentcomplete-always-returns-0.667558/

Bunn
H
0

Solved by just changing “obj.PercentComplete” by “obj.GetDownloadStatus().Percent”

IEnumerator OnLoad(AsyncOperationHandle obj)
      {
          while (obj.IsDone == false)
          {
              yield return new WaitForSeconds(.1f);
              progressImg.fillAmount = obj.GetDownloadStatus().Percent;
              percentCopmlete1.text = obj.GetDownloadStatus().Percent * 100f + "%".ToString();
          }
         
      }
Heathenism answered 9/3, 2021 at 17:1 Comment(0)
P
0

This line will fix it most likely, since you already have the dependencies downloaded.

Addressables.ClearDependencyCacheAsync(_scene);
Postmistress answered 12/12, 2023 at 16:58 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.