Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Error "The call is ambiguous between the following methods or properties" Unity3D #470

Unanswered
spiNkerZ asked this question in Q&A
Discussion options

Hello everyone Faced with such a problem after upgrading to Unity3D 202310.b18:

error CS0121: The call is ambiguous between the following methods or properties: 'Cysharp.Threading.Tasks.UnityAsyncExtensions.GetAwaiter(UnityEngine.AsyncOperation)' and 'UnityEngine.AsyncOperationAwaitableExtensions.GetAwaiter(UnityEngine.AsyncOperation)'

My code:

await UnityEngine.SceneManagement.SceneManager.LoadSceneAsync(ID);
``
I solved this problem in this way if anyone needs:

 AsyncOperation loadSceneHandler = UnityEngine.SceneManagement.SceneManager.LoadSceneAsync(ID);
 await loadSceneHandler.ToUniTask();
You must be logged in to vote

Replies: 2 comments 5 replies

Comment options

Warning

From the UniTask Readme:

In UniTask, await directly uses native timing, while WithCancellation and ToUniTask use specified timing. This is usually not a particular problem, but with LoadSceneAsync, it causes a different order of Start and continuation after await. So it is recommended not to use LoadSceneAsync.ToUniTask.

At first I used this and it seemed to work fine in editor and standalone windows builds. But when I tested in a UWP build (IL2CPP), the await loadSceneHandler.ToUniTask(); hold the whole app and all I got was a black screen.

You must be logged in to vote
0 replies
Comment options

UnityAsyncExtensions.GetAwaiter is disabled in UNITY_2023_1_OR_NEWER.

#if !UNITY_2023_1_OR_NEWER
// from Unity2023.1.0a15, AsyncOperationAwaitableExtensions.GetAwaiter is defined in UnityEngine.
public static AsyncOperationAwaiter GetAwaiter(this AsyncOperation asyncOperation)
{
Error.ThrowArgumentNullException(asyncOperation, nameof(asyncOperation));
return new AsyncOperationAwaiter(asyncOperation);
}
#endif

Why is it enabled?
You must be logged in to vote
5 replies
Comment options

I don't know...
I'm using Unity 2023年1月16日f1 and have the name conflict.
It seems UNITY_2023_1_OR_NEWER is false in my project (so the code is included), this is very strange.

Comment options

My issue is with Visual Studio.
The define are not properly set, so Visual Studio underline await SceneManager.UnloadSceneAsync("my_scene_name"); in red with error CS0121, but it's ok in Unity.

Comment options

How about regenerating csproj?
Delete the sln and csproj and have Unity regenerate them.

Comment options

Already done, and it doesn't fix preprocessor directives in Visual Studio.
I think it's because of some incompatibility of my Visual Studio version and the Unity Visual Studio package version, but I can't change easily them becuse my company computer doesn't have an access to the internet.
It's not a big issue for me, now I understood it's broken only in Visual Studio.

Comment options

I know I'm late to the conversation but in case it happens to someone else:
You need to set using UnityEngine; in the class you are setting your await or else it will try to get the AsyncOperation from LoadSceneAsync instead of the Awaitable version from Unity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

AltStyle によって変換されたページ (->オリジナル) /