DownloadDependencies causing LoadSceneAsync to fail

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:

public IEnumerator DownloadDependencies()
        {
            DateTime startTime = DateTime.Now;
           
            Log.Debug(() => "DownloadDependencies [Dependencies]");
            var loadResourceLocationsAsync =
                Addressables.LoadResourceLocationsAsync(DownloadManifest, Addressables.MergeMode.Union);
            while (!loadResourceLocationsAsync.IsDone)
            {
                var downloadStatus = loadResourceLocationsAsync.GetDownloadStatus();
                LoadingScreenInterface.SetLoadingScreenStatus("GetResources...", downloadStatus.Percent);
                Log.Debug(() => $"[Dependencies] LoadLocations: {downloadStatus.Percent} {downloadStatus.DownloadedBytes} / {downloadStatus.TotalBytes} \n {loadResourceLocationsAsync.DebugName}");
                yield return new WaitForSeconds(1);
            }

            if (loadResourceLocationsAsync.Status != AsyncOperationStatus.Succeeded)
            {
                Log.Error(() => $"[Dependencies] Failed to get resource locations " + loadResourceLocationsAsync.OperationException);
                LoadingScreenInterface.SetLoadingScreenStatus("FAILED", 0);
                isError = true;
                yield break;
            }
           
            Log.Debug(() => $"[Dependencies] loadResourceLocationsAsync.Result " + loadResourceLocationsAsync.Result.Count);
           
            var getDownloadSizeAsync = Addressables.GetDownloadSizeAsync(loadResourceLocationsAsync.Result);
            while (!getDownloadSizeAsync.IsDone)
            {
                LoadingScreenInterface.SetLoadingScreenStatus("GetDownload...", getDownloadSizeAsync.PercentComplete);
                yield return new WaitForSeconds(1);
            }

            if (getDownloadSizeAsync.Status != AsyncOperationStatus.Succeeded)
            {
                Log.Error(() => $"[Dependencies] Failed to getDownloadSizeAsync " + getDownloadSizeAsync.OperationException);
                LoadingScreenInterface.SetLoadingScreenStatus("FAILED", getDownloadSizeAsync.PercentComplete);
                yield break;
            }
           
            Log.Debug(() => $"[Dependencies] getDownloadSizeAsync result: " + getDownloadSizeAsync.Result);
           
            if (getDownloadSizeAsync.Result <= 0)
            {
                Log.Debug(() => $"[Dependencies] Nothing to download!");
                LoadingScreenInterface.SetLoadingScreenStatus("Download Ready", 1);
                yield break;
            }
           
            downloadDependenciesAsync = Addressables.DownloadDependenciesAsync(loadResourceLocationsAsync.Result);

            while (!downloadDependenciesAsync.IsDone)
            {
                var downloadStatus = downloadDependenciesAsync.GetDownloadStatus();
                Log.Debug(() => $"[Dependencies] DownloadStatus: {downloadStatus.Percent} - Downloaded :{downloadStatus.DownloadedBytes} / {downloadStatus.TotalBytes}");
                LoadingScreenInterface.SetLoadingScreenStatus("Downloading...", downloadStatus.Percent);
                yield return new WaitForSeconds(1);
            }

            if (downloadDependenciesAsync.Status != AsyncOperationStatus.Succeeded)
            {
                isError = true;
                Debug.LogError("[Dependencies] We failed to download dependencies! " + downloadDependenciesAsync.OperationException);
            }

            Log.Debug(() => $"[Dependencies] DownloadDependencies  after {(DateTime.Now - startTime).TotalSeconds} secs");
        }

[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?

1 Like

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…

2 Likes

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.

5 Likes

Came here to post the same findings.

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

2 Likes

Thanks - this helped!