I do not understand AsyncOperation...

Hello I learn unity since a week I realized more than 10 hours of learning but here I bug on a piece of code that I saw:

private string _currentLevelName = string.Empty

void LoadComplete(AsyncOperation ao)
{
    Debug.Log("Chargement terminer !");
}

public void LoadLevel(string levelName)
{
    AsyncOperation ao = SceneManager.LoadSceneAsync(levelName);
//Is here :
//ao.completed += LoadComplete;
_currentLevelName = levelName
}

I do not understand : ao.completed += LoadComplete;
Explain in detail what this does please !!
Thanks !

ao.completed += LoadComplete; adds the LoadComplete() function as a listener to the AsyncOperation completed event.

If you fully understood what this meant after 10 hours experience with programming C# then you’re far cleverer than me, which may very well be the case.

However, my advice would be to try and find some simpler examples to start with and work up to more complex stuff like events and delegates…

1 Like

Thank you for your reply

AsyncOperation also inherits YieldInstruction so it could be used in a Coroutine

1 Like