Search Unity

AsyncOperationHandle.PercentComplete not updating when given as a Parameter in Function

Discussion in 'Addressables' started by David_GameDev, Apr 26, 2019.

  1. David_GameDev

    David_GameDev

    Joined:
    Dec 25, 2016
    Posts:
    29
    Since 0.7.4 I´ve got a Problem with my loading screen. What I have been doing sofar was a simple Loadingscreen, with the function

    Code (CSharp):
    1. public IEnumerator ShowProgress(AsyncOperationHandle op)
    2.     {
    3.              //this also seemingly doesn´t work anymore. What I currently do, just for testing is instead of GetDownloadSize(op) I replace the op with the actual object key, at least for now.
    4.              Addressables.GetDownloadSize(op).Completed += (AsyncOperationHandle<long> getValue) => { Downloadsize = getValue.Result; finishedGettingInfo = true; };
    5.              yield return new WaitUntil(() => finishedGettingInfo);
    6.  
    7.         while (op.PercentComplete < 1)
    8.         {
    9.              progressBar.value = op.PercentComplete;
    10.              txtProgress.text = string.Format("{0:0.00}mb / {1:0.00}mb", (op.PercentComplete / 1000000) * 100, Downloadsize / 1000000);            
    11.              yield return new WaitForSeconds(0.01f);
    12.         }
    13.   }
    14.  

    Pretty simple loading screen which worked for any Addressables Load I had. However, since 0.7.4, the op.PercentComplete doesn´t update at all. It only updates when the operation is basically done and op.PercentComplete = 1; It worked before IAsyncOperation got replaced with AsyncOperationHandle. Any advice whether I just have an error in the code now or if I need a new approach for this because maybe the AsyncOperationHandle doesn’t work exactle the same as it did before as IAsyncOperation.
    And is it possible to get the object Key from AsyncOperationHandle?

    Thanks in advance
     
    CharBodman likes this.
  2. dbarile

    dbarile

    Joined:
    Apr 14, 2015
    Posts:
    14
    Same here. Using Addressables 7.5 Please advise. :eek:

    @unity_bill , you are our only hope!

    Code (CSharp):
    1. this.asyncOperationObjectLoad = this.experienceAsset.Instantiate();
    2.  
    3. if (!this.onCompleteCreated)
    4. {
    5.      this.onCompleteCreated = true;
    6.      this.asyncOperationObjectLoad.Completed += OnObjectLoaded;
    7. }
    8.  
    9. void Update()
    10. {
    11.         if (!this.isLoading)
    12.             return;
    13.  
    14.         if (this.onCompleteCreated)
    15.         {
    16.             this.progressBar.SetValue(this.asyncOperationObjectLoad.PercentComplete);
    17.         }
    18. }
     
    Last edited: May 4, 2019
  3. David_GameDev

    David_GameDev

    Joined:
    Dec 25, 2016
    Posts:
    29
    0.8.4. Still same Problem, PercentComplete from AsyncOperationHandle - Parameter not updating.
     
    CharBodman likes this.
  4. unity_bill

    unity_bill

    Joined:
    Apr 11, 2017
    Posts:
    1,053
  5. dbarile

    dbarile

    Joined:
    Apr 14, 2015
    Posts:
    14
    @unity_bill Any word on the progress complete issue? We're about ready to ship a product and were hoping there might be a solution by now. Thanks!
     
    CharBodman, faolad and David_GameDev like this.
  6. dbarile

    dbarile

    Joined:
    Apr 14, 2015
    Posts:
    14
    Using Addressables 1.1.5, is there a way to cancel a AsyncOperationHandle?

    I tried some of the following approaches, but no luck...

    Code (CSharp):
    1.  
    2. private AsyncOperationHandle asyncOperationObjectLoad;
    3.  
    4. public void LoadExperience()
    5. {
    6.           this.onCompleteCreated = true;//flag for Update()
    7.  
    8.           this.asyncOperationObjectLoad = this.experienceAsset.Instantiate();
    9.  
    10.           this.asyncOperationObjectLoad.Completed += OnObjectLoaded;
    11. }
    12.  
    13. public void DestroyLoadedAssets()
    14. {
    15.         if (this.loadedExperience != null)
    16.         {
    17.             Addressables.Release(this.loadedExperience);
    18.         }
    19.        
    20.         this.onCompleteCreated = false;
    21.  
    22.         this.asyncOperationObjectLoad.Completed -= OnObjectLoaded;//doesn't work
    23.  
    24.         StopAllCoroutines();//doesn't work
    25.  
    26.         this.asyncOperationObjectLoad = new AsyncOperationHandle();//doesn't work
    27. }
    Also, still not able to get a value for AsyncOperationHandle.PercentComplete. Is there some sort of workaround?

    For that matter, I'm doing the potential code in an Update loop, which is pretty janky to begin with. Is there a AsyncOperationHandle.onProgress or .onLoad to register to?

    Code (CSharp):
    1.  
    2. private void Update()
    3. {
    4.         if (!this.isLoading)
    5.             return;
    6.  
    7.         if (this.onCompleteCreated)
    8.         {
    9.             this.progressBar.SetValue(this.asyncOperationObjectLoad.PercentComplete);
    10.         }
    11.         else
    12.         {
    13.             this.progressBar.SetValue(0);
    14.         }
    15. }
    @unity_bill Or any other Unity staff. Any help would be much appreciated. Thank you!
     
  7. unity_bill

    unity_bill

    Joined:
    Apr 11, 2017
    Posts:
    1,053
    We had fixed some case earlier, but tracked down what should be the main failing scenario recently. The fix is in our repo and will be in the next release.

    not yet. We've looked into it. The problem is that some things you can do through addressable are cancel-able. Some not. So we haven't added this yet as we can't actually guarantee a reasonable behavior.

    no. the main thing that will ever have progress is the download. for that we're wrapping https://docs.unity3d.com/ScriptReference/Networking.UnityWebRequest.html which has no "on progress" callback. The update loop is probably the best place to work with that.
     
  8. CharBodman

    CharBodman

    Joined:
    Sep 20, 2018
    Posts:
    36
    Hey Bill , Do you have a rough estimation when this next release will be? We're trying to launch a production game asap and we need this PercentComplete bug fixed :confused:.

    Thanks !
     
  9. unity_bill

    unity_bill

    Joined:
    Apr 11, 2017
    Posts:
    1,053
    Either next week or the week after. Things are a little hard to nail down as a lot of the team is in and out on vacation over the summer. But I'm targeting fairly soon
     
    fabioColombini likes this.
  10. essamri

    essamri

    Joined:
    Nov 29, 2017
    Posts:
    2
    this is still an issue for me , is there any news ?
     
  11. mocerezo

    mocerezo

    Joined:
    Jan 21, 2013
    Posts:
    8
    is working now for me with Addressables v. 1.1.7
     
  12. essamri

    essamri

    Joined:
    Nov 29, 2017
    Posts:
    2
    i only get some value ex: 0.33, then 0.8, then 1
    not real progress
    is that what you got ?
     
    David_GameDev likes this.
  13. mocerezo

    mocerezo

    Joined:
    Jan 21, 2013
    Posts:
    8
    No, actually i got a smooth progress from 0 to 1 ( 0.1,..... 0.45,..... 0.6...0.8.... 1), im using a progress bar and is working fine.
     
  14. Bobbiii

    Bobbiii

    Joined:
    Jun 28, 2019
    Posts:
    18
    :::>_<::: I got the same problem
     
  15. Bobbiii

    Bobbiii

    Joined:
    Jun 28, 2019
    Posts:
    18
    When I use Addressables.GetDownloadSizeAsync
    the AsyncOperationHandle.PercentComplete is always 1
     
  16. davidla_unity

    davidla_unity

    Unity Technologies

    Joined:
    Nov 17, 2016
    Posts:
    763
    Hey @zhbd GetDownloadSizeAsync doesn't actually download anything, it just checks the location data for the download size. If Addressables is initialized this is basically a synchronous operation. The only reason you might see anything different than 1 on this operation is if Addressables hasn't finished initialization and we chain the GetDownloadSizeAsync op with the init op.

    @essamri what API are you using that you're checking the progress of? I can take a look at how that specific operation works and make sure we haven't missed something.
     
    unity_bill likes this.
  17. vitorfgd

    vitorfgd

    Joined:
    Nov 4, 2014
    Posts:
    27
    Do you have any updates on cancelling the
    AsyncOperationHandle
    ? I'm creating a game with 3 HUGE stages and pre-loading them before the user selects a stage to play, my goal is to stop the other two and continue downloading the requested stage.
     
    Mazak likes this.
  18. Mazak

    Mazak

    Joined:
    Mar 24, 2013
    Posts:
    226
    Yes, we need a way to get a good progress of the download
     
  19. vitorfgd

    vitorfgd

    Joined:
    Nov 4, 2014
    Posts:
    27
    I am still experiencing download percentages being only 0 or 1. There are no progress, even normalized.
     
  20. trunghieu974

    trunghieu974

    Joined:
    Jun 19, 2015
    Posts:
    25
    1. Is there anyway to get download percentages? I still get just 0 or 1.
     
  21. timbokoppers

    timbokoppers

    Joined:
    Nov 14, 2016
    Posts:
    71
    Any news on this topic ?
     
    AndersLightbulb likes this.
  22. ProtoTerminator

    ProtoTerminator

    Joined:
    Nov 19, 2013
    Posts:
    586
    Updated to 1.6.0 and still seeing this issue in webgl, Unity 2019.1.14.

    Interestingly, I did see a couple 0.33333 and one 0.666667, but the other several hundred were either 0 or 1.
    I thought maybe it was because my mac is downloading so fast that it doesn't have time to register any in-betweens. So I fired it up on my chromebook and even throttled the network, but it still only got 0 or 1, and it didn't get any in betweens.

    @DavidUnity3d @unity_bill
     
  23. davidla_unity

    davidla_unity

    Unity Technologies

    Joined:
    Nov 17, 2016
    Posts:
    763
    @ProtoTerminator just curious, have you tried any other builds (like Standalone?). To the best of my knowledge we should be reporting the underlying operations percent complete (or a calculated one in the event of chain operation or group operations). I'd be curious to double check that you're getting more granularity if you used UnityWebRequest directly to download the asset bundle. I'm unsure.

    What APIs are you using that you're seeing this on?
     
  24. timbokoppers

    timbokoppers

    Joined:
    Nov 14, 2016
    Posts:
    71
    I have the same problem as @ProtoTerminator is describing. Only for an iOS build. I load the addressables from a google bucket. Keeps at 0 for a long time... and in the end you see really quickly 0.6667 and BOOM it's there..
    Not a steady progress from 0 to 1.
     
  25. ProtoTerminator

    ProtoTerminator

    Joined:
    Nov 19, 2013
    Posts:
    586
    @DavidUnity3d Hm, interesting. I just ran a test with directly using UnityWebRequests to download pngs and json files, and it elicited the same behavior (only printing 0 and 1). I was just using Addressables.LoadAsset<T>(string) btw.

    After digging through the patch notes for 2019.2 and 2019.3, I saw
    WebRequest: Fixed an issue with UploadHandlerFile properties contentType and progress. ([URL='https://issuetracker.unity3d.com/issues/uploadhandlerfile-dot-contenttype-cannot-be-set-and-always-returns-text-slash-plain']1197177[/URL])
    in 2019.2.19. Is that where this issue is fixed?

    Sadly, my team's project has been unable to run WebGL after upgrading the engine, so we've been stuck on 2019.1.14 for a while.
     
  26. davidla_unity

    davidla_unity

    Unity Technologies

    Joined:
    Nov 17, 2016
    Posts:
    763
    @ProtoTerminator I'll have to triage on the different versions to see but that sounds very likely to be the case. If there's an issue with what the underlying operation is reporting as it's percent complete there won't be anything we can do about that on the Addressables side unfortunately.

    Sorry to hear you're having trouble with WebGL on updated versions of the Editor. I don't know if you've submitted any WebGL bugs or talked to them on their forums but maybe they can help you out there?
     
  27. timbokoppers

    timbokoppers

    Joined:
    Nov 14, 2016
    Posts:
    71
    @DavidUnity3d can you confirm it should work? I have (and based on other comment, more people do) exactly the same issue. We build for iOS and are loading a prefab with dependencies. The PercentComplete is not working as expected.

    Can you 100% confirm it should work in a smooth manner giving you back the exact percentage loaded (including the dependencies loaded)
     
  28. NikuPotato

    NikuPotato

    Joined:
    Feb 20, 2020
    Posts:
    3
    In my case (Unity 2019.1.14),
    AsyncOperationHandle.PercentComplete
    works fine with 1.2.4, but not working properly with 1.6.2.
    It looks working fine between 0 - 0.5, then it suddenly jumps up to 1 after 0.5.

    So I looked at ChainOperation.cs (1.6.2), and I found
     m_WrappedOp.IsValid() 
    always returns false in below.

    Code (CSharp):
    1.        
    2. protected override float Progress
    3.         {
    4.             get
    5.             {
    6.                 float total = 0f;
    7.  
    8.                 if (m_DepOp.IsValid())
    9.                     total += m_DepOp.PercentComplete;
    10.                 if (m_WrappedOp.IsValid())
    11.                     total += m_WrappedOp.PercentComplete;
    12.  
    13.                 return total / 2;
    14.             }
    15.         }
    16.  
    Now I get why my
    AsyncOperationHandle.PercentComplete
    jumps 0.5 to 1, but is this how supposed to behave with 1.6.2?
     
    timbokoppers likes this.
  29. davidla_unity

    davidla_unity

    Unity Technologies

    Joined:
    Nov 17, 2016
    Posts:
    763
    @NikuPotato Ah, quite right. We'll get that changed.
     
  30. OneManArmy3D

    OneManArmy3D

    Joined:
    Jun 2, 2011
    Posts:
    191
    On WebGL PercentComplete always returns 0.
     
    RobRab2000 likes this.
  31. nikosurfing

    nikosurfing

    Joined:
    Mar 11, 2014
    Posts:
    45
    Before my hand getting dirty, is it already fixed or not? i am currently use 1.7.5
     
  32. CharBodman

    CharBodman

    Joined:
    Sep 20, 2018
    Posts:
    36
    Ya you should be good.
     
  33. nikosurfing

    nikosurfing

    Joined:
    Mar 11, 2014
    Posts:
    45
    Thank you :)
     
  34. ArchieFPV

    ArchieFPV

    Joined:
    Jun 10, 2019
    Posts:
    1
    I'm seeing this issue with Addressables 1.7.5 and Unity 2019.3.10f1.

    I'm trying to download large prefab assets.

    In my android build I see some progression....but it's not consistent or smooth. It will jump from 0 to .33 to .6667 then load the asset. Usually it hangs on 0 for sometime then immediately loads.

    I'm using
    InstantiateAsync(
    ). Should I be using
    Addressables.DownloadDependencies()
    before instantiating?
     
  35. Ghetaldus

    Ghetaldus

    Joined:
    Jul 15, 2017
    Posts:
    46
    I still have same problem. Using latest addressables version (1.8.3). Platform is android, unity version is 2019.3.9f1 and it is getting files from google bucket. It seems to stay at 0% for most of download time and then suddenly jumps up to 67%, after it almost directly goes to 100% and then it is done downloading.
     
    Last edited: Apr 27, 2020
  36. Alberos

    Alberos

    Joined:
    Nov 13, 2014
    Posts:
    8
    I see similar issue with the PercentComplete from AsyncOperationHandle returned from DownloadDependenciesAsync not being accurate.

    In my case, I called DownloadDependenciesAsync on the splash scene to download pretty much every asset in my app. It immediately jumped to around 60-80% and then start growing from there all the way to 100%. The PercentComplete cannot be used to even 'approximately' show the total byte downloaded. The asset is pretty big (~500 mb), I need something that can display the total byte downloaded.

    I'm using Android player connected to local Wifi network in my house and Unity's Addressable Hosting to serve the package.

    Also the downloading does not pause even if I press the home button to "exit" (in user's point of view) the app. Do I need to call something to make it pause? It seem like this should be built in behavior.


    EDIT: Sorry forget to mention.
    - I'm on Unity 2019.2.17f1 with Addressable 1.8.3
    - There is no cached data before the download started. The GetDownloadSizeAsync was called and waited to finish before the DownloadDependenciesAsync with the same label is called.
     
    pahe likes this.
  37. Wawro01

    Wawro01

    Joined:
    Apr 23, 2014
    Posts:
    44
    I cant believe this is not fixed till now. This was issue since since beginning.

    Here is what I have done:

    Addressables.DownloadDependencies() bahaves the way that it tries to load things that are cached or local as well. This is the reason why progress will jump to some number after calling it. My workaround or fix has 2 steps:
    • Get only resources actually that needs to be downloaded
    • Fix progress for GroupOperation
    Code (CSharp):
    1.  
    2. //Get locations to download - keys is List<object> of things to download
    3. var loadResourceLocations =
    4.                 Addressables.LoadResourceLocationsAsync(keys, Addressables.MergeMode.Union);
    5.             await loadResourceLocations.Task;
    6.             var locations = new List<IResourceLocation>(loadResourceLocations.Result);
    7.  
    8. //Get unique dependencies of locations that are not cached and not local
    9. List<IResourceLocation> result = new List<IResourceLocation>();
    10. foreach (var resourceLocation in locations)
    11. {
    12.    foreach (var resourceLocationDependency in resourceLocation.Dependencies)
    13.    {
    14.       long sz = 0;
    15.  
    16.       if (resourceLocationDependency.Data is ILocationSizeData sizeData)
    17.          sz += sizeData.ComputeSize(resourceLocationDependency, Addressables.ResourceManager);
    18.  
    19.       if (sz > 0)
    20.       {
    21.          result.Add(resourceLocationDependency);
    22.       }
    23.    }
    24. }
    25.  
    26. //Download dependencies - this is equivalent of DownloadDependencies() method
    27. var r = Addressables.LoadAssetsAsync<IAssetBundleResource>(result, null);
    28.  
    29. //this progress will be much better but still wrong because of GroupOperation progress implementation
    30. var progress = r.PercentComplete;
    31.  
    32.  
    Code (CSharp):
    1.  
    2. //My changes in GroupOperation.cs
    3. private IList<IResourceLocation> m_Locations;
    4.         protected override float Progress
    5.         {
    6.             get
    7.             {
    8.                 List<AsyncOperationHandle> allDependentOperations = new List<AsyncOperationHandle>();
    9.                 allDependentOperations.AddRange(Result);
    10.  
    11.                 foreach(var handle in Result)
    12.                     handle.GetDependencies(allDependentOperations);
    13.  
    14.  
    15.                 //CUSTOM
    16.                //Unity just give you averages of all dependencies so if one has 1MB and 500MB it will show progress 0.5 when frist dependency was downloaded
    17.                 if (m_Locations !=null &&
    18.                     m_Locations.Count == allDependentOperations.Count &&
    19.                     m_Locations.All(x => x.Data is AssetBundleRequestOptions))
    20.                 {
    21.                     float sum = 0;
    22.                     float downloaded = 0f;
    23.                     for (var index = 0; index < allDependentOperations.Count; index++)
    24.                     {
    25.                         var operation = allDependentOperations[index];
    26.                         if (m_Locations[index].Data is AssetBundleRequestOptions d)
    27.                         {
    28.                             sum += d.BundleSize;
    29.                             downloaded += operation.PercentComplete * d.BundleSize;
    30.                         }
    31.                     }
    32.  
    33.                     return downloaded / sum;
    34.                 }
    35.              
    36.              
    37.  
    38.                 if (Result.Count < 1)
    39.                     return 1f;
    40.                 float total = 0;
    41.                 for (int i = 0; i < allDependentOperations.Count; i++)
    42.                     total += allDependentOperations[i].PercentComplete;
    43.                 return total / allDependentOperations.Count;
    44.             }
    45.         }
    46.  
    47.  
    48.       //You need to pass locations from places this function is called
    49.         public void Init(List<AsyncOperationHandle> operations, IList<IResourceLocation> locations)
    50.         {
    51.             m_Locations = locations;
    52.             Result = new List<AsyncOperationHandle>(operations);
    53.         }
     
    Rafael_CS, pahe and timbokoppers like this.
  38. pahe

    pahe

    Joined:
    May 10, 2011
    Posts:
    543
    I'll give @Wawro01 changes a try. Currently with Addressables 1.8.3 the PercentComplete is only giving out 0, 0.5 or 1 for me and renders it pretty much useless to calculate the real progress.
     
  39. DevarajHexaware

    DevarajHexaware

    Joined:
    Oct 24, 2018
    Posts:
    1
    I'm also having the same problem, any solution for proper progress loading from 0 to 100 percent?
     
  40. RobRab2000

    RobRab2000

    Joined:
    Nov 28, 2012
    Posts:
    29
    Any updates on when this might be fixed?

    In WebGL it seems to be particularly bad (in the editor sometimes I'll get 0.5 but in webgl it always seems to be 0 or 1). Could it be an issue with it expecting to do async across different threads which aren't available in WebGL?
     
  41. aka3eka

    aka3eka

    Joined:
    May 10, 2019
    Posts:
    32
    The problem persisted up till Addressables 1.8.4.
    Thank God it was fixed in 1.9.2 and now progress works just fine (I have checked this with MacOS standalone only).
     
  42. Ghetaldus

    Ghetaldus

    Joined:
    Jul 15, 2017
    Posts:
    46
    Can confirm that this works better now with 1.9.2 in android as well, although not perfectly yet.
    Now it seems to jump to 50% at once and then start downloading and updating percent correctly from there up to 100%.
     
  43. ProtoTerminator

    ProtoTerminator

    Joined:
    Nov 19, 2013
    Posts:
    586
    That's probably because they check if addressables was initialized before running any request. Does it work properly if you initialize first before requesting assets?
     
  44. Ghetaldus

    Ghetaldus

    Joined:
    Jul 15, 2017
    Posts:
    46
    Have not tested doing preloading first. I am using InstantiateAsync directly and that works fine, except for that it starts with jumping to 50%.
    I have found this in latest documentation though and that is probably why it behaves as it do:
    upload_2020-6-7_13-1-46.png
     
  45. better_walk_away

    better_walk_away

    Joined:
    Jul 12, 2016
    Posts:
    291
    My PercentageComplete didn't start from 0, either. It started from something like 0.875 or 0.9, not sure why it behaved like this.
     
    Deleted User likes this.
  46. Deleted User

    Deleted User

    Guest

    For code bellow. The PercentComplete returns 1f at first, than 0.5f, 0.83f and after that is slowly increasing.

    Unity 2019.4.0f1
    Addressables 1.8.4

    Given label contains 5 prefabs about 52MB.

    Code (CSharp):
    1. var handle = Addressables.DownloadDependenciesAsync(label, true);
    2. handle.Completed += unused => { Debug.Log("Assets are loaded."); };
    3.  
    4. while (!handle.IsDone)
    5. {
    6.     Debug.Log($"Loading...{handle.PercentComplete}.");
    7.     await Task.Yield();
    8. }
     
  47. Deleted User

    Deleted User

    Guest

    This version works like charm.


    Code (CSharp):
    1. var handle = Addressables.DownloadDependenciesAsync(label, true);
    2. handle.Completed += unused => { Debug.Log("Assets are loaded."); };
    3. // FIX
    4. await Task.Yield();
    5.  
    6. while (!handle.IsDone)
    7. {
    8.     Debug.Log($"Loading...{handle.PercentComplete}.");
    9.     await Task.Yield();
    10. }
     
  48. Lucas-Hehir

    Lucas-Hehir

    Joined:
    Jul 2, 2014
    Posts:
    41
    Yeah the progress value is, by default, kind of goofballs. Mine was starting at 0.8625 on the first frame of the operation and went for hundreds of frames in tiny increments. This is my goofy work-around, it seems to work well.

    Code (CSharp):
    1. if (Math.Abs(percentCompleteOffset) < Mathf.Epsilon)
    2. {
    3.     percentCompleteOffset = op.PercentComplete;
    4.          
    5.     Debug.Log($"percentCompleteOffset starts at [{percentCompleteOffset}]");
    6. }
    7.      
    8. var percentComplete = (op.PercentComplete - percentCompleteOffset) / (1.0f - percentCompleteOffset);
     
  49. Revolter

    Revolter

    Joined:
    Mar 15, 2014
    Posts:
    216
    I experience the same behaviour with Addressables 1.13.1 in Unity 2018.4.17f1 when loading Local AssetReferences

     
  50. Kobald-Klaus

    Kobald-Klaus

    Joined:
    Jun 20, 2014
    Posts:
    127
    WHY IS THIS STILL NOT WORKING?
    That is the f*cking easiest thing to implement. Downloaded bytes / total size. It seems there is not even a possibility to access downloaded bytes data. WHY?
    I am really getting mad. It costs so much time to f*ck arround for nothing !!!!