The issue of calling Addressables.DownloadDependenciesAsync
following by Addressables.LoadAssetAsync
is a regression introduced in Addressables 1.21.15:
- Before Addressables 1.21.12: you can use
Addressables.DownloadDependenciesAsync
following by Addressables.LoadAssetAsync
. The downloaded asset bundles won’t be loaded into memory until Addressables.LoadAssetAsync
is called. This is the expected behaviour.
- In Addressables 1.21.12: you can still use
Addressables.DownloadDependenciesAsync
following by Addressables.LoadAssetAsync
. But the downloaded asset bundles will be loaded into memory inside Addressables.DownloadDependenciesAsync
.
- In Addressables 1.21.15 and later versions: you can’t use
Addressables.DownloadDependenciesAsync
following by Addressables.LoadAssetAsync
. Because the AssetBundleResource
instance which is created inside Addressables.DownloadDependenciesAsync
won’t load the asset bundle and Addressables.LoadAssetAsync
will use this AssetBundleResource
instance directly, which doesn’t have an asset bundle.
Calling Addressables.Release(downloadHandle)
will release the AssetBundleResource
instance created inside Addressables.DownloadDependenciesAsync
. After that, when Addressables.LoadAssetAsync
is called, it will create a new AssetBundleResource
instance which can load an asset bundle.
Here is a part of the diff of AssetBundleProvider.cs for Addressables 1.21.12:
@@ -423,23 +422,6 @@ namespace UnityEngine.ResourceManagement.ResourceProviders
/// <returns>The asset bundle.</returns>
public AssetBundle GetAssetBundle()
{
- if (m_AssetBundle == null)
- {
- if (m_downloadHandler != null)
- {
- m_AssetBundle = m_downloadHandler.assetBundle;
- m_downloadHandler.Dispose();
- m_downloadHandler = null;
- }
- else if (m_RequestOperation is AssetBundleCreateRequest)
- {
- m_AssetBundle = (m_RequestOperation as AssetBundleCreateRequest).assetBundle;
- }
- }
-
-#if ENABLE_ADDRESSABLE_PROFILER
- AddBundleToProfiler(Profiling.ContentStatus.Active, m_Source);
-#endif
return m_AssetBundle;
}
@@ -737,6 +734,9 @@ namespace UnityEngine.ResourceManagement.ResourceProviders
#if ENABLE_ADDRESSABLE_PROFILER
AddBundleToProfiler(Profiling.ContentStatus.Active, m_Source);
#endif
+ m_AssetBundle = downloadHandler.assetBundle;
+ downloadHandler.Dispose();
+ downloadHandler = null;
m_ProvideHandle.Complete(this, true, null);
m_Completed = true;
}
As you can see, the code insde GetAssetBundle
method was removed and downloadHandler.assetBundle
was used to load the asset bundle, regradless of whether it’s downloading or not.
Here is a part of the diff of AssetBundleProvider.cs for Addressables 1.21.15:
@@ -734,7 +741,11 @@ namespace UnityEngine.ResourceManagement.ResourceProviders
#if ENABLE_ADDRESSABLE_PROFILER
AddBundleToProfiler(Profiling.ContentStatus.Active, m_Source);
#endif
- m_AssetBundle = downloadHandler.assetBundle;
+ if (!(m_ProvideHandle.Location is DownloadOnlyLocation))
+ {
+ // this loads the bundle into memory which we don't want to do with download only bundles
+ m_AssetBundle = downloadHandler.assetBundle;
+ }
downloadHandler.Dispose();
downloadHandler = null;
m_ProvideHandle.Complete(this, true, null);
As you can see, the code was changed to not load the asset bundle when it’s downloading, but GetAssetBundle
method still returns m_AssetBundle
directly, which is null.
This issue still exists in latest versions(1.21.19 and 2.0.6 as for now).