- Home /
How to use AsyncOperation.completed?
Hello
I want to use the AsyncOperation.completed delegate but there's not much information about it online, and I'm a bit new to Actions in c#
https://docs.unity3d.com/ScriptReference/AsyncOperation-completed.html
Can somebody explain to me how to implement it in code?
Can you give me more context of your implementation please.
Hello @sacredgeometry $$anonymous$$y implementation would be to check when the next scene has finished loading and when it has finished, subscribe the next void method. Actually after talking to a friend I understand how it works.
void Start ()
{
var ao = Scene$$anonymous$$anager.LoadSceneAsync(2);
ao.completed += O => { LoadingNext(); };
}
void LoadingNext()
{
// *do something*
}
Answer by Bieere · Aug 11, 2019 at 04:42 PM
Actions are great, i personally use them a lot for my projects.
when an action is declared Action<AsyncOperation>
the type within the angled brackets is the return type of the action. So there are two ways for you to use this.
1. Lambda Operation
AsyncOperation operation = new AsyncOperation();
operation.completed += (asyncOperation) =>
{
//Do stuff here with returned value asyncOperation
};
2. Function
void Test()
{
AsyncOperation operation = new AsyncOperation();
operation.completed += OperationOnCompleted;
}
private void OperationOnCompleted(AsyncOperation obj)
{
throw new NotImplementedException();
}
Thanks! the function solution is what I've been looking for.
Your answer
Follow this Question
Related Questions
How to implement a loading screen for a procedurally-generated level? 1 Answer
How to get references when load a new scene? 0 Answers
How to make a list of Actions or methods? 1 Answer
Capture reference to recently loaded scene asycn 0 Answers
Loading scene with LoadSceneAsync freezes and progress jumps from 0% to 90% 2 Answers