When preloading assets through a label using Addressables.DownloadDependenciesAsync it returns a null task.
When using LoadAssetsAsync<GameObject> with the same key(label), it goes just fine and it returns the gameobject asset.
The GetDownloadSizeAsync won’t work either with the label. It always returns 0, probably because it is null as well.
Build Bundles
Packed mode
Go into play mode and click the download button. → receives 0 size
then after clicking the Yes button it will try to download the dependencies but it returns a null task.
public AssetReferenceGameObject PrefabRef;
[ContextMenu("Delete Cache")]
public void DeleteCache()
{
Caching.ClearCache();
}
public string Dependency = "Preload";
public TextMeshProUGUI DownloadText;
public async void GetDownloadText()
{
DownloadText.text = $"Are you sure you want to download {((await Addressables.GetDownloadSizeAsync(Dependency).Task) / 1024f / 1024f)} mb of assets?";
}
public async void OnDownloadButtonClick()
{
// Null Reference Exception
await Addressables.DownloadDependenciesAsync(Dependency).Task;
}
public async void GetMeForced()
{
var asset = await Addressables.LoadAssetAsync<GameObject>(Dependency).Task;
Instantiate(asset);
}
It’s also happening in my end. I always getting a null Task when I try to return it for an asset that doesn’t have dependencies (I know that because trying to do GetDependencies() always returns a null exception with a message of no deps). The stacktrace is the following:
And the strange piece of code for the Tasks that doesn’t have an specific result (Task) is the following:
System.Threading.Tasks.Task<object> IAsyncOperation.Task
{
get
{
return Task as System.Threading.Tasks.Task<object>;
}
}
Is trying to cast a Task but debugging this part I saw that is not initialized yet.
A workaround seems to be use a Coroutine to await the AsyncOperationHandle but with that you lose the advantages of Tasks.
Sounds like we have a couple issues all wrapped up into one post. For one, I think we should always return a valid op, even if the op is done or not doing anything (to prevent nullRef’s). So that’s a bug.
Second, in your sample project everything is set up to be local (loading from streaming assets). As such, GetDownloadSize will return 0, and DownloadDependencies should finish immediately with nothing to download.
Ah my bad. It seems I’ve been a bit too quick in setting up a minimal build.
I’ve set them to remote and hooked up a local hosting service. It does show the size.
Just when clicking yes to actually download them it throws a null reference for the task.
So yeah GetDownloadSize works indeed. Wondering what went wrong before in my bigger project. I will have to debug that later on, maybe the same problem that I forgot to put them remote. If I end up finding another bug I’ll let you know.
@unity_bill Any update on this? I just updated to using Addressables only to find that I cannot download any assets due to a null reference error on Addressables.DownloadDependenciesAsync().
Any workaround until there is a fix?
Is there any example code that does show the right way for pre-downloading all remote assets using Addressables? Like how asset bundles are downloaded at loading time? (I couldn’t find any examples in either basic or advanced examples. And the documentation does not have any example either)
Requesting an updated link to addressables documentation for the latest version.
Is it still broken? I feel like we fixed this, but being a months old post, I might be mis-remembering. If you are still seeing it, please outline the repro. 2. not sure exactly what you need.
3. Unity Addressable Asset System | Package Manager UI website but the best way to get the latest docs is to either watch the “new release” thread on this forum, or click “view docs” from within package manager.
Regarding point 2: Getting Started | Package Manager UI website Downloading in Advance
Calling the Addressables.DownloadDependenciesAsync() method loads the dependencies for the address or label that you pass in. Typically, this is the asset bundle.
There is no example project of this case anywhere that I could find.
Addressables.DownloadDependenciesAsync(“spaceHazards”);
Here if “spaceHazaards” is a resource label (and has been applied to a bunch of assets).
I get exception at runtime: “Key is invalid exception”.
I really just want to see one sample project that actually does this. It would be great, if you can send me a link to a sample project that uses this technique for a remote resource that is NOT using Unity editor for hosting.
I am currently doing a wierd way to getting my asset bundles downloaded by making a call to a known asset reference that is part of my Remote Group
Addressables.DownloadDependenciesAsync(“known_asset_reference_in_remote_group”);
And it works. But i wish I could pass in the resource label instead.
4:
After doing the above I do get the download to work from a remote resource (azure CDN), but I get this error on device.
Unity 2019.2.10f1
It already has Strip Engine code disabled. This is a blocker for me now.
Could not produce class with ID 1108.
This could be caused by a class being stripped from the build even though it is needed. Try disabling 'Strip Engine Code' in Player Settings.
..
..
(Filename: ./Runtime/Serialize/PersistentManager.cpp Line: 1543)
Calling DownloadDependenciesAsync or LoadAssetsAsync should either both work (If the catalog knows about the key/label/whatever) or both not work (if the catalog does not know about it).
So please add a little more detail…
Download fails, but Load works - this would be really weird. if this is the case, definitely open a bug against unity with a repro.
both download and load fail - the catalog doesn’t have your key. Likely you either have a typo in the label (note it’s case sensitive) or your label isn’t on anything as of the last build.
For the code stripping issue, this is likely a bug that will require a repro project and an official ticket against Unity. That being said, it would probably be best to resolve your invalid key issue first, and download through our system. I don’t know how these could be related, but if you are reporting a bug that’s built upon a workaround, it’s a lot harder to track down.
it did not work as in it threw an exception.
Not sure why this should not work.
I think the best way for me to figure out and produce a repro is to have a single source of truth from an official example instead of me trying to make this work.
Everything is easier with an example.
Most likely its me trying to use the system in a way that you don’t want me to
So I request you to provide an example project that does “Remote Download” which uses DownloadDependenciesAsync method.
Regarding point 4: I found that I still get the errors on device but it does not stop me from loading into the game. So not sure how serious that bug is. Maybe i will only know what it broke after i do a thorough testing. So for now. I am able to load into the game good.
(btw, loving this new system. Wishing you guys make a whole lot of sample projects to cover all possible cases)
Found the main reason why DownloadDependenciesAsync function or many other functions related to Addressables did not work and were flaky…
Reason: The “Clear Cache button” is broken. Yes even in the 1.4.0 version.
To fix all my issues I now manually delete 2 sections everytime i build bundles.
Delete /Library/com.addressables.
%APPDATA%/locallow///com.addressables.
Deleting these 2 folder fixes all the problems for me.
Hmm, I used DownloadDependenciesAsync() yesterday and it worked fine. Though I didn’t know it can take Label name…I passed AssetReference in it (So something like Addressables.DownloadDependenciesAsync(EnemyAssetReference) and it loaded wonderfully. I’m using 1.10
public Task DownloadDependenciesTask(<Label>) {
var handle = Addressables.DownloadDependenciesAsync(<Label>);
var completionSource = new TaskCompletionSource<object>();
handle.Completed += op =>
{
if (op.Status == AsyncOperationStatus.Succeeded)
{
completionSource.TrySetResult(handle.Result);
};
}
return completionSource.Task;
}