Question by
Noctre · May 02, 2021 at 08:00 PM ·
c#scripting problemassetdatabaseloading during runtime
Addressables.LoadAssets only loading first asset in the list
I am trying to load four textures using Addressables, the system works when I load them one by one with Addressables.LoadAsset, but when I pass a list of addresses (strings) into Addressables.LoadAssets only the first one gets loaded.
I tried logging anything from ResourceManager.ExceptionHandler, but no exceptions were thrown.
Here is the code:
public static class Coins
{
private const string TEX_COIN_ADDRESS = "Textures/Pickups/Coin/";
private static List<string> textureAddresses = new List<string>() { "1", "2", "5", "10" };
private static Dictionary<int, Texture2D> textures = new Dictionary<int, Texture2D>(4) { { 1, null }, { 2, null }, { 5, null }, { 10, null } };
private static AsyncOperationHandle<IList<Texture2D>> loadHandle;
public static bool IsLoaded { get {
bool result = true;
foreach (Texture2D tex in textures.Values)
if (tex == null)
result = false;
return result;
} }
public static event Action OnLoaded;
public static void LoadAssets()
{
NokLog.Log("Loading coin textures...");
List<string> addresses = new List<string>();
foreach (string address in textureAddresses)
addresses.Add(TEX_COIN_ADDRESS + address);
loadHandle = Addressables.LoadAssetsAsync<Texture2D>(addresses, TextureLoaded, Addressables.MergeMode.None);
loadHandle.Completed += (AsyncOperationHandle<IList<Texture2D>> handle) => {
if (handle.Status == AsyncOperationStatus.Succeeded) {
NokLog.LogHighlight("Coin textures loaded | " + IsLoaded);
OnLoaded?.Invoke();
}
else {
NokLog.DeepLogError("Coin texture load failed");
}
};
}
private static void TextureLoaded(Texture2D result)
{
textures[int.Parse(result.name)] = result;
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613033158im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Issues using two scripts. 1 Answer
why the Timer isn't working 0 Answers
Issues with Jump Script in C# 0 Answers
Help me the toggle is stuck 1 Answer
What is the correct way to learn unity scripting ? 2 Answers