Search Unity

PercentComplete goes to 1 immediately, IsDone stays false a long time (loading a scene)

Discussion in 'Addressables' started by aojiso, Sep 7, 2019.

  1. aojiso

    aojiso

    Joined:
    Jun 6, 2013
    Posts:
    3
    Hello,

    I am using trying to switch to addressables for scene loading. I have it basically working, but I'm having trouble getting a useful value from my AsyncOperationHandle.PercentComplete for a loading bar. PercentComplete goes to 1 immediately, but IsDone remains false for a long time (several seconds).


    The AssetGroup contains just the scene I'm loading. My build settings do not contain this scene, and instead there is single minimal title screen. The scene I'm loading is somewhat complicated, with a lot high-res textures (I'm helping someone else with a project, not expecting a miracle).

    In Looking at the builds, the level AssetGroup is taking up most of the file size, so seems all the scene dependecies were correctly identified.

    Here is the code I tried most recently. I am using SceneManager.LoadSceneAsync, because I wanted to see if it was an issue with the scene loading, and not the addressables, but the scene load takes way less time than the DownloadDepencies operation. I get the same symptoms when I try `LevelToLoadAddressable.LoadSceneAsync()`.

    I feel like I'm missing something fundamental. Thanks for looking.

    Code (csharp):
    1.  
    2. public class TestSceneLoad : MonoBehaviour
    3. {
    4.     [SerializeField]
    5.     AssetReference LevelToLoadAddressable;
    6.  
    7.    
    8.     float curProgress = -1;
    9.  
    10.     string statusMessage = "";
    11.  
    12.     //Called by a UGUI button
    13.     public void LoadLev()
    14.     {
    15.         var asop = Addressables.DownloadDependenciesAsync(LevelToLoadAddressable);
    16.         StartCoroutine(LoadLevRoutine(asop));
    17.     }
    18.  
    19.     IEnumerator LoadLevRoutine(AsyncOperationHandle asop)//<SceneInstance>
    20.     {
    21.         curProgress = asop.PercentComplete;
    22.         float startTime = Time.unscaledTime;
    23.  
    24.        
    25.         statusMessage = "loading addressable asset (not done)";
    26.         while (!asop.IsDone)
    27.         {
    28.             //stuck in this loop, for a long time
    29.             //even though asop.PercentComplete == 1
    30.             curProgress = asop.PercentComplete;
    31.             yield return new WaitForSeconds(.1f);
    32.            
    33.         }
    34.  
    35.         statusMessage = "loading scene (not done)";
    36.         curProgress = 0;
    37.         AsyncOperation loadSceneOp = SceneManager.LoadSceneAsync("Level1", LoadSceneMode.Single);
    38.    
    39.         while (loadSceneOp.isDone == false)
    40.         {
    41.  
    42.  
    43.             curProgress = loadSceneOp.progress;
    44.            
    45.             yield return null;
    46.  
    47.         }
    48.         statusMessage = "(done)";
    49.     }
    50.  
    51.     private void OnGUI()
    52.     {
    53.         GUI.Label(new Rect(100, 100, 500, 250), statusMessage + " : " + curProgress);
    54.     }
    55. }
    56.  
    57.  
     
  2. aojiso

    aojiso

    Joined:
    Jun 6, 2013
    Posts:
    3
    I just tried updating addressables to 1.2.3, cleaning and rebuilding, but no change.
     
  3. PieterAlbers

    PieterAlbers

    Joined:
    Dec 2, 2014
    Posts:
    246
    I might have a similar issue - did you get this to work?
     
  4. davidla_unity

    davidla_unity

    Unity Technologies

    Joined:
    Nov 17, 2016
    Posts:
    763
    What version are you using, @PieterAlbers ? We've made changes to percent complete recently so your issue may be resolved in a more recent version.
     
  5. PieterAlbers

    PieterAlbers

    Joined:
    Dec 2, 2014
    Posts:
    246
    The build was made in 2019.2.10.
    I did do some more debugging and got the percentage to start from 0 again and properly count towards 1. It stays there though and the isdone is never called.
     
  6. davidla_unity

    davidla_unity

    Unity Technologies

    Joined:
    Nov 17, 2016
    Posts:
    763
    Sorry, not your Editor version, your Addressables package version.
     
  7. PieterAlbers

    PieterAlbers

    Joined:
    Dec 2, 2014
    Posts:
    246
    Sorry for the confusion. I am not using addressables atm - however I am downloading assetbundles (old style) and I am experiencing similar issues. My code looks pretty much identical.

    If my posts causes confusion please remove them.

    Pieter