- Home /
Addressables: PercentComplete 0 during asset download.
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
Answer by DhiaSendi · Mar 09, 2021 at 05:01 PM
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();
}
}
Answer by aka3eka · Feb 17, 2020 at 07:03 PM
Hi spanagiotis, Did you manage to solve the issue #3?
BTW, there is more info on this issue here: https://forum.unity.com/threads/0-7-4-addressables-downloaddependencies-percentcomplete-always-returns-0.667558/
Your answer
Follow this Question
Related Questions
Pause AssetBundle download if app goes on background iOS 1 Answer
Which way is better to handle AssetBundle management 2 Answers
Asset Bundles show in Editor, but not on camera. 0 Answers
How to import the object from server to unity 2 Answers
How to flush assetBundle if its download fails in between ? 0 Answers