Anyone know how I can pass through an extra variable (a string) with
Addressables.LoadAssetAsync<Sprite>("Path").Completed += Function;
If it’s not obvious, I want to pass through an extra variable to “function” after the asset load is completed.
1 Like
joe_nk
2
Hey, this is more of a C# question, but to answer - just assign a lambda to your Completed event and call your function via that:
private static void LoadMySprite() {
const string mySpritePath = "Path";
const string mySpriteName = "Name";
Addressables.LoadAssetAsync<Sprite>(mySpritePath).Completed += handle => Function(handle, mySpriteName);
}
private static void Function(AsyncOperationHandle<Sprite> handle, string myString) {
if (handle.Status == AsyncOperationStatus.Succeeded) {
Sprite mySprite = handle.Result;
Debug.Assert(myString == "Name");
}
}
4 Likes
I learn something everyday. Thank you it works perfectly!
2 Likes