Search Unity

[0.7.4] Addressables.DownloadDependencies: PercentComplete always returns 0

Discussion in 'Addressables' started by TobiasW, Apr 25, 2019.

Thread Status:
Not open for further replies.
  1. TobiasW

    TobiasW

    Joined:
    Jun 18, 2011
    Posts:
    91
    Hello,

    I've upgraded from 0.6.8 to 0.7.4 to get an Addressables.GetDownloadSize() that takes already cached AssetBundles into account (which works, hurray), but now the following code displays 0 every frame until it's done:

    Code (CSharp):
    1.  
    2. var downloadDependenciesOp = Addressables.DownloadDependencies(label.labelString);
    3. while (!downloadDependenciesOp.IsDone)
    4. {
    5.      Debug.Log(downloadDependenciesOp.PercentComplete);
    6.      yield return null;
    7. }
    8.  
    9. Debug.Log("Done!");
    10. }
    This was working with 0.6.8.
     
    CharBodman likes this.
  2. unity_bill

    unity_bill

    Joined:
    Apr 11, 2017
    Posts:
    1,053
    we'll look into it. thanks.
     
  3. unity_bill

    unity_bill

    Joined:
    Apr 11, 2017
    Posts:
    1,053
    Just to double check, you are doing this in a player (not in the editor) and the bundles are up on some server, right? And the `Debug.Log(downloadDependenciesOp.PercentComplete);` gets called many times?
     
  4. TobiasW

    TobiasW

    Joined:
    Jun 18, 2011
    Posts:
    91
    This is happening both in the editor and the Android player if I remember correctly, and the bundles are indeed up on some server. The exact same code was printing proper percentages with 0.6.8, so you can (probably) rest assured that the code is working correctly.

    And I should've specified: This is part of a coroutine. So yes, "Debug.Log(downloadDependenciesOp.PercentComplete);" gets called many times (and prints 0 every time until the whole operation is done).
     
    CharBodman likes this.
  5. unity_bill

    unity_bill

    Joined:
    Apr 11, 2017
    Posts:
    1,053
    Got it, just had to check :)
     
    CharBodman and TobiasW like this.
  6. David_GameDev

    David_GameDev

    Joined:
    Dec 25, 2016
    Posts:
    29
    Still seems to be a problem with 1.1.4
     
    CharBodman and fabioColombini like this.
  7. wangyucheng1992

    wangyucheng1992

    Joined:
    Feb 19, 2019
    Posts:
    59
  8. fabioColombini

    fabioColombini

    Joined:
    Dec 9, 2013
    Posts:
    30
    Yes @David_GameDev and @unity_bill
    same for me v1.1.4.

    • Scene "Main" is in a server remotly.
    • Play Mode Script = Packed Play Mode
    The scene takes a time to be loaded and just "0" are showed.

    My example:
    Code (csharp):
    1. IEnumerator LoadMainScene()
    2.     {
    3.         AsyncOperationHandle<SceneInstance> tmp = Addressables.LoadSceneAsync("Main");
    4.         tmp.Completed += OnLoadSceneCompleted;
    5.  
    6.         while (!tmp.IsDone)
    7.         {
    8.             print("Update: " + tmp.PercentComplete);
    9.             yield return null;
    10.         }
    11.     }
     
    CharBodman and David_GameDev like this.
  9. CristianGarciaJ

    CristianGarciaJ

    Joined:
    Apr 13, 2018
    Posts:
    8
    Hi everybody,

    A workaround that works for me is:


    operation.GetDependencies(deps);

    float percentComplete = 0;

    for (int i = 0; i < deps.Count; ++i)
    {
    percentComplete += deps.PercentComplete;
    }

    percentComplete /= deps.Count;

    Cheers!
     
    David_GameDev likes this.
  10. CharBodman

    CharBodman

    Joined:
    Sep 20, 2018
    Posts:
    36
    Where are you getting deps?
     
    David_GameDev likes this.
  11. CristianGarciaJ

    CristianGarciaJ

    Joined:
    Apr 13, 2018
    Posts:
    8
    From the AsyncOperationHandle
     
    David_GameDev likes this.
  12. fabioColombini

    fabioColombini

    Joined:
    Dec 9, 2013
    Posts:
    30
    @CristianGarciaJ could you explain this line in more detail?

    operation.GetDependencies(deps);
     
    David_GameDev likes this.
  13. faolad

    faolad

    Joined:
    Jan 27, 2013
    Posts:
    118
    I think this is more clear:
    Code (CSharp):
    1.   private static float calculatePercentComplete(AsyncOperationHandle asyncOperation)
    2.         {
    3.             var deps = new List<AsyncOperationHandle>();
    4.             asyncOperation.GetDependencies(deps); // deps is added to! (weird API...)
    5.             float percentCompleteSum = 0;
    6.             foreach (var asyncOperationHandle in deps)
    7.             {
    8.                 percentCompleteSum += asyncOperationHandle.PercentComplete;
    9.             }
    10.             return percentCompleteSum / deps.Count;
    11.         }
     
  14. CristianGarciaJ

    CristianGarciaJ

    Joined:
    Apr 13, 2018
    Posts:
    8
    Yes, the response of faolad is correct.

    Sorry for the misunderstanding :)
     
    David_GameDev likes this.
  15. CharBodman

    CharBodman

    Joined:
    Sep 20, 2018
    Posts:
    36
    Unfortunately this is still broken in 1.1.5.


    I believe this will always return 1 if you use a single label to load multiple dependencies.
    I'm going to have to test it some more.
     
  16. androshchuk-vladyslav

    androshchuk-vladyslav

    Joined:
    Dec 13, 2015
    Posts:
    127
    The same, operation should return progress of all dependencies.
     
  17. Favo-Yang

    Favo-Yang

    Joined:
    Apr 4, 2011
    Posts:
    464
    Report a bug please. Unity has a team helps reproduce bug, and then goes into their internal progress quickly.

    Forum is also helpful for discussion and avoiding duplicated report though.
     
    unity_bill likes this.
  18. caochao88_unity

    caochao88_unity

    Joined:
    May 16, 2019
    Posts:
    26
    basicly, the only thing i want to know is loading progress of asset, which from 0 to 1. and I don't care about percentComplete. unity should provide a property like handle.progress.
     
    CharBodman likes this.
  19. mido4sure

    mido4sure

    Joined:
    Jul 28, 2015
    Posts:
    2
    still same problem in asset bundles progress is not good showing from 0 to 1.
     
    aka3eka likes this.
  20. mido4sure

    mido4sure

    Joined:
    Jul 28, 2015
    Posts:
    2
    this problem still exit in 1.1.10
     
    aka3eka and Dotberrys like this.
  21. aka3eka

    aka3eka

    Joined:
    May 10, 2019
    Posts:
    32
    The problem still persists in Addressables 1.6.2.
    It looks Unity guys just don't care :(
     
  22. aka3eka

    aka3eka

    Joined:
    May 10, 2019
    Posts:
    32
    Thanks for the code!

    I managed to dig with debugger that AsyncOperationHandle.Result holds a List<AsyncOperationHandle> of asset bundles that are loaded because requested asset bundles depends on them (plus the requested asset bundle itself).
    And every one of them has its own PercentComplete field. But the example above will calculate simple average of their PercentComplete not taking into account real sizes of asses bundles being loaded. Which gives quite distorted results if some bundles have significantly larger sizes than others. And I didn't find any means to get theses sizes of bundles. The only solution could be making your own JSON file with bundle sizes when building Addressables.

    It is definitely the bug inside of Addressables system.
     
    faolad likes this.
  23. unity_bill

    unity_bill

    Joined:
    Apr 11, 2017
    Posts:
    1,053
    general note: don't use 1.1.10 even though package manager in 2019.3 will suggest it. Look for latest & update (currently 1.6.2).

    We thought we fixed this in 1.2.4. Quoting the changelog:

    [1.2.4] - 2019-09-13
    • Further improvement to the % complete calculations.
      • Note that this is an average of dependency operations. Meaning a LoadAssetsAsync call will average the download, and the loading progress. DownloadDependenciesAsync currently has one extra op, so the download will crawl to 50%, then jump to done (we will look into removing that). Similarly any op that is called before Addressables init's will jump to 50% once init is done.

    So if it's still a problem for you, please file a bug through Unity with a repro project or explain your situation more clearly here.
     
    Last edited: Feb 19, 2020
  24. aka3eka

    aka3eka

    Joined:
    May 10, 2019
    Posts:
    32
    Thanks for answering here.

    Posting a bug to Unity support if quite a long story, so I'll try to explain here and will post the bug if it won't help.

    I have a test project with 1 asset group that contains:
    - The Scene1 (marked as addressable)
    - The GameObject on the Scene1 that holds references to two video files in the project. These files are 20Mb each and are used just as ballast to prevent the bundle to load instantly.
    - When the bundle is built (on MacOS) it consists of three files: scene1_assets_all.bundle, scene1_scenes_all.bundle and scene1_unitybuiltinshaders.bundle. I upload the the package (all bundles and catalog file with it's hash) to AWS S3 bucket. And the addressables group is configured so that Load Path directs to AWS S3 public URL.
    - There is also another scene - Loader that is included in the application build (Built in data). This scene has a GameObject that has component attached that loads Scene1 using LoadSceneAsync(). And there is a coroutine with the following code:

    Code (CSharp):
    1. private IEnumerator SceneLoadProgress(AsyncOperationHandle handle)
    2.     {
    3.         while (!handle.IsDone)
    4.         {
    5.             UpdateCaption(handle.PercentComplete.ToString("0.00") + " - " + calculatePercentComplete(handle).ToString("0.00"));
    6.             yield return new WaitForSeconds(.5f);
    7.         }
    8.     }
    9.  
    The coroutine is started right after LoadSceneAsync() call.
    The method UpdateCaption() just outputs the string passed to a text field.
    The method calculatePercentComplete() does exactly what [faolad] posted above (calculates percent complete via GetDependencies()).

    The system is configured to run the Play mode script "Use existing build". I get the same result in both Unity IDE Play mode and built application. And the result is the following:
    0.00 - 0.00
    0.00 - [value increases steadily]
    ...
    0.00 - 0.99
    1.00 - 1.00

    The versions are:
    - Unity 2019.3.0f6
    - Addressables 1.6.2
    - MacOS Mojave 10.14.6

    Fun fact: depending on the number on bundles and dependencies sometimes PercentComplete() returns 0.5 while loading instead of 0.0.
     
    AlexandreDelan likes this.
  25. aka3eka

    aka3eka

    Joined:
    May 10, 2019
    Posts:
    32
    The problem persisted up till Addressables 1.8.4. It's fixed in 1.9.2.
     
  26. prasetion

    prasetion

    Joined:
    Apr 3, 2014
    Posts:
    28
    great to know if the percentageComplete error has fixed @aka3eka
    is it correct if i wrote my code like this to know loaded asset process??


    Code (CSharp):
    1. IEnumerator InitData()
    2.         {
    3.  
    4.             AsyncOperationHandle<GameObject> handle = _Data.LoadAssetAsync<GameObject>();
    5.  
    6.             while (!handle.IsDone)
    7.             {
    8.                 Debug.Log(handle.PercentComplete);
    9.                 yield return null;
    10.             }
    11.  
    12.             if (handle.Status == AsyncOperationStatus.Succeeded)
    13.             {
    14.                 Debug.Log(handle.Result);
    15.                 Addressables.Release(handle);
    16.             }
    17.         }

    Because when i get the log console, the output always 0.5
    i doubted if my code was correct
     
  27. aka3eka

    aka3eka

    Joined:
    May 10, 2019
    Posts:
    32
    The code looks ok for me for testing purpose.
    Do you test it using remote server? My observations say that loading bundles locally (from filesystem) doesn't really report real progress even in "Use existing build" mode.
     
  28. manuelgoellnitz

    manuelgoellnitz

    Joined:
    Feb 15, 2017
    Posts:
    397
    I started using addressables with 1.8.4. in this version, when i use

    dl = Addressables.DownloadDependenciesAsync(AdressableLabel);

    dl.PercentComplete starts at 0,66 and goes up to 1.
    when I use

    dl = Addressables.LoadResourceLocationsAsync(AdressableLabel);

    dl.PercentComplete stays 0.

    Then I discovered this thread where it says "Fixed in 1.9.2". So I Upgraded to the latest version 1.15.1.
    Now the behavior is:
    With DownloadDependenciesAsync, PercentComplete on some bundles is 0 and on others 0,97 to 1
    With LoadResourceLocationsAsync, PercentComplete starts at 0,75 and goes up to 1.

    So did I something wrong or is the bug not fixed at all?
     
  29. manuelgoellnitz

    manuelgoellnitz

    Joined:
    Feb 15, 2017
    Posts:
    397
    Ok i digged a bit more here in the forum.

    dl = Addressables.DownloadDependenciesAsync(AdressableLabel);
    var state = dl.GetDownloadStatus();
    Debug.Log(state.percent);

    seems to work from 0 to 1.

    Which is really odd, because I use a custom AssetBundleProvider (there the Percent value and the DownloadStatus is set) and in my Version the Downloadstatus is updated with the percent-value (becasue I use a Webrequest class which does not provide downloaded bytes).

    So the bug is somewhere in the Adressables code, that the Callback for CompletePercent is not called, but the one for DownloadStatus is.
     
  30. perholmes

    perholmes

    Joined:
    Dec 29, 2017
    Posts:
    296
    Same here, bug seems to not be fixed at all.
     
    SavedByZero and faolad like this.
  31. perholmes

    perholmes

    Joined:
    Dec 29, 2017
    Posts:
    296
    There are some funny interactions between the number of bundles, size of bundles, and also whether the server is local.

    I have something that works now to produce fluid progress using the number of bytes download, and it also calculates a current download speed. See https://github.com/perholmes/UnityAutoBundles, in Test Scripts, AssetLoader.cs and Main.cs.
     
Thread Status:
Not open for further replies.