Useage Question : Awaiting AsyncOperationHandle<SceneInstance>
See original GitHub issueHi,
I have created a static helper class with a function that uses Addressable to load a scene and return the AsyncOperationHandle<SceneInstance> for later use. The AsyncOperationHandle<SceneInstance> is is not intended to be awaited, it is just used to call Addressables.UnloadSceneAsync() later on.
I am having an issue awaiting the AsyncOperationHandle<SceneInstance> where i recive this message:
“yield SceneInstance is not supported on await IEnumerator or IEnumerator.ToUniTask(), please use ToUniTask(MonoBehaviour coroutineRunner) instead.”
I don’t have a MonoBehaviour instance to use with ToUniTask(MonoBehaviour coroutineRunner) or actually understand why it is necessary.
Any help on how best to structure this would be really appreciated, thank you!
public static async UniTask<AsyncOperationHandle<SceneInstance>> LoadSceneAsync(object key, LoadSceneMode loadMode = LoadSceneMode.Single, bool activateOnLoad = true, int priority = 100)
{
var asyncOphandle = Addressables.LoadSceneAsync(key, loadMode, activateOnLoad, priority);
// These commented out lines cause: "yield SceneInstance is not supported on await IEnumerator or IEnumerator.ToUniTask(), please use ToUniTask(MonoBehaviour coroutineRunner) instead."
//await asyncOphandle;
//await asyncOphandle.ToUniTask();
// I can't do this as I don't have a MonoBehaviour to pass in
//await asyncOphandle.ToUniTask(this);
// This works, but is very inefficient as its using Unity's implementation
// await asyncOphandle.Task;
// This is what I have settled on for now, is there a better way?
while (!asyncOphandle.IsDone)
await UniTask.Yield();
return asyncOphandle;
}
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (3 by maintainers)
Top GitHub Comments
Indeed,
AsyncOperationHandle<TObject> : IEnumerator
may execute its extension method. But ifUniTask.Addressables
is enabled, AddressableAsyncExtensions has priority. Maybe this method is defined in anotherasmdef
and there is no reference toUniTask.Addressables
? AddUniTask.Addressables
as a reference.If code is grayed out, yes.