I tried calling Addressables.LoadAssetsAsync from a static class (not a Monobehaviour/singleton) like this:
public static async Task<bool> FetchPlayerProfiles(string assetLabel)
{
var fetchOp = Addressables.LoadAssetsAsync<PlayerProfile>(new List<object> {assetLabel}, null, Addressables.MergeMode.None);
if (!fetchOp.IsValid())
{
Debug.LogWarning($"[{assetLabel}] is not a valid asset operation key.");
Addressables.Release(fetchOp);
return false;
}
await fetchOp.Task;
if (fetchOp.Status == AsyncOperationStatus.Failed)
{
Debug.LogException(biomeFetchOp.OperationException);
Addressables.Release(fetchOp);
return false;
}
if (fetchOp.Result == null)
{
Debug.LogWarning("Fetched asset list is null!");
Addressables.Release(fetchOp);
return false;
}
currentProfiles = new List<PlayerProfile>(fetchOp.Result.OrderBy(profile => profile.id));
return true;
}
And hot damn it did not like that one bit. Hard crash, no errors, just completely locks up. I guess you can’t do this? I’m very new to async/await as well so I might be getting something about that wrong…
I’m using
Addressables 1.9
Unity 2019.3.4f1