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");
}