Search Unity

Can I get the progress of a screen loading with Addressables?

Discussion in 'Addressables' started by Kairei, Oct 19, 2018.

  1. Kairei

    Kairei

    Joined:
    Aug 16, 2018
    Posts:
    4
    When loading an asset with addressables, there is an overload that takes an Action<IAsyncOperation<T>> paramter in addition to the "Completed" delegate:

    Addressables.LoadAssets<GameObject>("avatar", OnAssetLoading).Completed += OnAssetLoaded;

    This lets me get notifications for both progress and completion. However, when loading a scene, the "Completed" event is there, but there doesn't seem to be a way to get the progress:

    Addressables.LoadScene(sceneAddress).Completed += OnSceneLoaded;

    Two questions:

    1. Am I missing something or is there no way to get scene downloading progress?

    2. While I can load assets using the above, and then choose to actually instantiate them at a time of my choice, with the scene, it just gets loaded and shown when the download is completed... is there any way to have the scene just download and let me call the normal "SceneManager.Load" on it at a time of my choice?
     
  2. unity_bill

    unity_bill

    Joined:
    Apr 11, 2017
    Posts:
    1,053
    joanpescador and Cfirzi like this.
  3. CrispyCritter

    CrispyCritter

    Joined:
    May 11, 2018
    Posts:
    19
    I am digging up an oldie here but i got stuck into addressables about 3 weeks ago and really enjoying them they have allowed me to think on a much bigger scale but i am struggling with it lol while its simple to call these async ops and yield and even get percentComplete the problem here addressables has its own plans so you ask for a percent on a download so something like

    heres my testing setup so far

    my app is a 3D product catalog and each product is a 3D model around 100mb in size these are all hosted remotely so they can be downloaded and cached lets say i have 500 models it would make sense to go this direction with addressables

    so after setting up a simple list of assets refferences from there this is displayed in a UI scroll list on the screen the then it shows the asset download size (Addressables.GetDownloadSizeAsync()) this returns the size of 0 if its cached. so far so good my setup work this is where the odd things happen.

    the button for downloading the asset runs this code
    Code (CSharp):
    1.   public  void DownloadAsset()
    2.     {
    3.         StartCoroutine(DoDownload());
    4.     }
    5.  
    6.     IEnumerator DoDownload()
    7.     {
    8.         var dl = Addressables.DownloadDependenciesAsync(_AssetReference);
    9.         dl.Completed += (AsyncOperationHandle) =>
    10.         {
    11.             DownloadComplete();
    12.  
    13.         };
    14.  
    15.         while (dl.PercentComplete < 1 && !dl.IsDone)
    16.         {
    17.             Debug.Log("Downloading Asset: " + dl.PercentComplete.ToString());
    18.             yield return null;
    19.         }
    20.  
    21.     }
    That does work but the value returned on the percentComplete is odd it goes from 0 to 0.5 then starts growing from there and ends at like .7 addressables is clealy doing other things i am asking it to do one this but it gives me progress on that but not the other bits its doing or as some like to say the magic lol

    how would you go about getting more control over an asset download lets say you wanted to display the download size and the progress bar would show the downloaded amount?.

    The numbers that come back from the async percentComplete ops are useless i am on version 1.6
     
  4. stevenchristian20

    stevenchristian20

    Joined:
    Dec 23, 2019
    Posts:
    29
    Were you able to get it working? I am trying to have a download bar as well as have the UI scroll setup for downloadble assets, but I am stuck.
     
  5. CrispyCritter

    CrispyCritter

    Joined:
    May 11, 2018
    Posts:
    19

    well kinda, i had to park my RnD but i am back on it now ill keep you posted
     
  6. stevenchristian20

    stevenchristian20

    Joined:
    Dec 23, 2019
    Posts:
    29
    great I am kinda at that point now with my RnD. So much time lost with no ROI
     
  7. Jribs

    Jribs

    Joined:
    Jun 10, 2014
    Posts:
    154
    @CrispyCritter

    It sounds like your code is working as intended. If you have a small bundle you are downloading, your updates will not hit every decimal between 0 and 1. It downloads in chunks so it is probably downloading it in a couple chunks.

    And your code is also checking for percentage < 1, which means once it hits 100%, you are not hitting that Debug statement.

    It will also often be completed but the percentComplete value will not be 1, so I have to manually consume it as 1 when the download finishes.

    Other than that, I have no issues downloading large files and seeing the download percentage
     
  8. stevenchristian20

    stevenchristian20

    Joined:
    Dec 23, 2019
    Posts:
    29
    @CrispyCritter Could you share how you are doing this? or maybe DM me? I am working on an AR Book with multiple chapters is a series. Having a scroll list of chapters with a download size if it is cached, maybe the answer to a problem I am having.
     
  9. CrispyCritter

    CrispyCritter

    Joined:
    May 11, 2018
    Posts:
    19
    To be honest i have given up due to to much magic and the control i need i just can not get with addressable
    i have moved over to this asset instead
    https://forum.unity.com/threads/simpler-alternative-to-addressables.820998/#post-5576029

    Addressables is great but not for single developers like my self
     
    stevenchristian20 likes this.
  10. vadimtihonyuk

    vadimtihonyuk

    Joined:
    Feb 26, 2018
    Posts:
    32
    I spend some time and found minimal possible solution for now:
    upload_2020-5-22_16-12-8.png


    In Library\PackageCache\com.unity.addressables@1.8.3\Runtime\ResourceManager\ResourceProviders\WebRequestQueue.cs need to add lines above
    And then you are able to get actual download progress:
    upload_2020-5-22_16-7-32.png
     
    jterry, phobos2077 and aka3eka like this.
  11. aka3eka

    aka3eka

    Joined:
    May 10, 2019
    Posts:
    32
    The problem is fixed in Addressables 1.9.2.
     
    VEA_Games likes this.
  12. jterry

    jterry

    Joined:
    Oct 30, 2014
    Posts:
    9
    @vadimtihonyuk I followed your pattern, but return an overall percent complete.

    Code (CSharp):
    1.    
    2. public static class CustomWebRequestQueue
    3.     {
    4.         public static float GetPercentCompleteHack()
    5.         {
    6.             var activeRequets = WebRequestQueue.s_ActiveRequests;
    7.  
    8.             if (activeRequets.Count <= 0)
    9.                 return 0;
    10.  
    11.             float sum = 0;
    12.  
    13.             for(int i = 0; i < activeRequets.Count; i++)
    14.             {
    15.                 sum += activeRequets[i].webRequest.downloadProgress;
    16.             }
    17.  
    18.             return sum / activeRequets.Count;
    19.         }
    20.     }
    21.  
     
  13. Jon50

    Jon50

    Joined:
    Jan 28, 2018
    Posts:
    5
    What I came up with for Addressables.DownloadDependenciesAsync was WaitUntil inside a coroutine with a simple bool. I did not test but, this might also work for LoadSceneAsync. It would be something like this:


    Code (CSharp):
    1. private IEnumerator LoadAssets(string label)
    2.     {
    3.         var isDone = false;
    4.  
    5.         var download = Addressables.DownloadDependenciesAsync(label);
    6.         download.Completed += (operation) =>
    7.         {
    8.             isDone = true;
    9.             _slider.value = _slider.maxValue;
    10.         };
    11.  
    12.         while (!isDone)
    13.         {
    14.             _slider.value = download.PercentComplete;
    15.             yield return 0f;
    16.         }
    17.  
    18.         yield return new WaitUntil(() => isDone);
    19.     }

    I'm not sure the last line is needed because of the while loop, but in my case, I'm also getting the resources locations, which is before the download and it works for me.