Hello guys, I was wondering how to go about loading a folder marked as an addressable that contains different assets of different types and subfolders.
The use case is: An application that loads little minigames, each mini game would be a specific address, and the user would decide to download Minigame A or Minigame B.
So far I’ve been able to load GameObjects, or Sprites, or Scenes, but not an entire folder of different type of assets. For instance, what type should I put on “GameObject” instead of GameObject when trying to load the folder marked as an addressable?
Addressables.LoadAssetAsync<GameObject>()
If someone could put me in the right direction It would be great.
You can’t load a folder, but if you assign a label to a folder it will add that same label for all of its content, so you can load all assets through that label (so you could load every Object with that given label).
Even if I load the assets by label, I would do something like:
Addressables.LoadAssetsAsync<GameObject>(MyLabelString, null).Completed += objects =>
{
// some code
};
But, given that the assets inside the folder are from different types, what should I put instead of “GameObject”? Or should it be done in a different way?
Hello Bruno, sorry to bother again. So, I succesfully managed to load one of the assets inside the folder marked as addressable using LoadAssetAsync, however I’m having trouble loading multiple using the LoadAssetsAsync<> method as this requires an object for the key parameter instead of a string. I read some answers including this one: https://discussions.unity.com/t/766163 regarding this issue, I managed to successfully compile passing a string array as a parameter with only one string inside (the name of the label).
However I get a similar exception mentioned by Jaimi in his thread:
Exception encountered in operation UnityEngine.AddressableAssets.Initialization.InitializationOperation, result='', status='Succeeded' - Chain<IList`1,IResourceLocator>: ChainOperation of Type: System.Collections.Generic.IList`1[System.Collections.Generic.IList`1[UnityEngine.Object]] failed because dependent operation failed
Exception of type 'UnityEngine.AddressableAssets.InvalidKeyException' was thrown., Key=System.String[]
My question is, how should I pass the name of my label as an object key as required by LoadAssetsAsync?
You’re right, this code worked perfectly. Don’t know why mine didn’t the only difference was that my callback was being passed as a parameter instead of a lambda function, also using the third parameter (the one where MergeMode is specified) anyways, thanks for the help and the quick reply. Have a nice one