Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question DownloadDependencies causing LoadSceneAsync to fail

Discussion in 'Addressables' started by KingKRoecks, Sep 25, 2023.

  1. KingKRoecks

    KingKRoecks

    Joined:
    Jul 28, 2013
    Posts:
    145
    Whenever I attempt to load my addressable scenes for the first time, they fail to resolve with this bug:

    2023/09/24 20:06:29.298 8583 8602 Error Unity Scene 'Assets/Scenes/AddressableScene.unity' couldn't be loaded because it has not been added to the build settings or the AssetBundle has not been loaded.

    Whenever my app starts, I download from an array of strings as my manifest.
    One of the dependencies that I'm loading is the "AddressableScene", which has that as both a Key and an PackedAsset name, like how the addressable LoadyDungeons sample has their scenes.

    After first load, or clearing local and retrying, I successfully download and then fail to load the scene after the download completes. The next time I load the app, it works though.

    Am I doing something wrong?

    This is what my code for loading the dependencies looks like:

    Code (CSharp):
    1. public IEnumerator DownloadDependencies()
    2.         {
    3.             DateTime startTime = DateTime.Now;
    4.            
    5.             Log.Debug(() => "DownloadDependencies [Dependencies]");
    6.             var loadResourceLocationsAsync =
    7.                 Addressables.LoadResourceLocationsAsync(DownloadManifest, Addressables.MergeMode.Union);
    8.             while (!loadResourceLocationsAsync.IsDone)
    9.             {
    10.                 var downloadStatus = loadResourceLocationsAsync.GetDownloadStatus();
    11.                 LoadingScreenInterface.SetLoadingScreenStatus("GetResources...", downloadStatus.Percent);
    12.                 Log.Debug(() => $"[Dependencies] LoadLocations: {downloadStatus.Percent} {downloadStatus.DownloadedBytes} / {downloadStatus.TotalBytes} \n {loadResourceLocationsAsync.DebugName}");
    13.                 yield return new WaitForSeconds(1);
    14.             }
    15.  
    16.             if (loadResourceLocationsAsync.Status != AsyncOperationStatus.Succeeded)
    17.             {
    18.                 Log.Error(() => $"[Dependencies] Failed to get resource locations " + loadResourceLocationsAsync.OperationException);
    19.                 LoadingScreenInterface.SetLoadingScreenStatus("FAILED", 0);
    20.                 isError = true;
    21.                 yield break;
    22.             }
    23.            
    24.             Log.Debug(() => $"[Dependencies] loadResourceLocationsAsync.Result " + loadResourceLocationsAsync.Result.Count);
    25.            
    26.             var getDownloadSizeAsync = Addressables.GetDownloadSizeAsync(loadResourceLocationsAsync.Result);
    27.             while (!getDownloadSizeAsync.IsDone)
    28.             {
    29.                 LoadingScreenInterface.SetLoadingScreenStatus("GetDownload...", getDownloadSizeAsync.PercentComplete);
    30.                 yield return new WaitForSeconds(1);
    31.             }
    32.  
    33.             if (getDownloadSizeAsync.Status != AsyncOperationStatus.Succeeded)
    34.             {
    35.                 Log.Error(() => $"[Dependencies] Failed to getDownloadSizeAsync " + getDownloadSizeAsync.OperationException);
    36.                 LoadingScreenInterface.SetLoadingScreenStatus("FAILED", getDownloadSizeAsync.PercentComplete);
    37.                 yield break;
    38.             }
    39.            
    40.             Log.Debug(() => $"[Dependencies] getDownloadSizeAsync result: " + getDownloadSizeAsync.Result);
    41.            
    42.             if (getDownloadSizeAsync.Result <= 0)
    43.             {
    44.                 Log.Debug(() => $"[Dependencies] Nothing to download!");
    45.                 LoadingScreenInterface.SetLoadingScreenStatus("Download Ready", 1);
    46.                 yield break;
    47.             }
    48.            
    49.             downloadDependenciesAsync = Addressables.DownloadDependenciesAsync(loadResourceLocationsAsync.Result);
    50.  
    51.             while (!downloadDependenciesAsync.IsDone)
    52.             {
    53.                 var downloadStatus = downloadDependenciesAsync.GetDownloadStatus();
    54.                 Log.Debug(() => $"[Dependencies] DownloadStatus: {downloadStatus.Percent} - Downloaded :{downloadStatus.DownloadedBytes} / {downloadStatus.TotalBytes}");
    55.                 LoadingScreenInterface.SetLoadingScreenStatus("Downloading...", downloadStatus.Percent);
    56.                 yield return new WaitForSeconds(1);
    57.             }
    58.  
    59.             if (downloadDependenciesAsync.Status != AsyncOperationStatus.Succeeded)
    60.             {
    61.                 isError = true;
    62.                 Debug.LogError("[Dependencies] We failed to download dependencies! " + downloadDependenciesAsync.OperationException);
    63.             }
    64.  
    65.             Log.Debug(() => $"[Dependencies] DownloadDependencies  after {(DateTime.Now - startTime).TotalSeconds} secs");
    66.         }
     
  2. nugao

    nugao

    Joined:
    Nov 17, 2011
    Posts:
    20
    [1.21.15] - 2023-08-03
    • Fixed an issue where using binary catalogs causes a crash on Android with ARM7.
    • DownloadDepedenciesAsync no longer loads asset bundles into memory
    • Fixed an exception getting thrown in the Addressables Report when drilling into a bundle chain

    So, how to load asset into memory?

    Can anyone help us?
     
    KingKRoecks likes this.
  3. KingKRoecks

    KingKRoecks

    Joined:
    Jul 28, 2013
    Posts:
    145
    Thanks for the link.

    I see, so there's been a change that made this behavior happen. From everything I've seen in the Addressables code, it sounds like there's a lot of changes happening without properly accounting for edge-cases and failures.

    I was hunting a bug a day ago related to the corrupt GlobaHashId being set incorrectly in prefab mode, this was in the netcode package.

    So is there a call to manually load the content into memory now? LoadSceneAsync apparently isn't it...
     
    Last edited: Sep 25, 2023
  4. nugao

    nugao

    Joined:
    Nov 17, 2011
    Posts:
    20
    Like my problem, you need RELEASE the AsyncOperationHandle of DownloadDependenciesAsync, when the download has finished. then the LoadAssetAsync will Succeed.

    I don't know, why need to release handle. maybe there's internal resource locker.
     
    andreiagmu and KingKRoecks like this.
  5. KingKRoecks

    KingKRoecks

    Joined:
    Jul 28, 2013
    Posts:
    145
    Came here to post the same findings.

    It works fine, so long as you release the download async handle.
     
    andreiagmu likes this.