Answer the question
In order to leave comments, you need to log in
Is it possible to use "async ValueTask" in Unity?
Unity Addressables suggests creating items asynchronously. Wrote the following code:
public async void SpawnItem(ItemInfo itemInfo, Transform parentPos)
{
GameObject item = await SpawnAsset(itemInfo.itemName, parentPos);
//действия с item
}
public async ValueTask<GameObject> SpawnAsset(string itemName, Transform spawnPoint)
{
for (int i = 0; i < addressableAssets.Count; i++)
{
string storeName = LocationShortName(addressableAssets[i].InternalId);
if (itemName != storeName) continue;
GameObject spawnedObject = await Addressables.InstantiateAsync
(addressableAssets[i], spawnPoint.position, spawnPoint.rotation, spawnPoint).Task;
spawnedObjects.Add(spawnedObject);
return spawnedObject;
}
return null;
}
Answer the question
In order to leave comments, you need to log in
You can't do it in a unit, because ValueTask is too new a feature.
But you probably do n't need it.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question