- Home /
Invoke and Execution Order
Hello,
In the Unity manual you can view the execution order.
(Link: https://docs.unity3d.com/Manual/ExecutionOrder.html )
However, I can not see in it exactly when Invokes are executed.
Does anyone know at what point Invokes are executed?
Answer by Lysander · Dec 31, 2017 at 10:40 AM
If you place an Invoke in Awake, then it'll always wait until after Start, Enabled, and the first Update and LateUpdate functions have passed before actually triggering, no matter how small of a delay you put. Any time beyond that though and it's completely random- they could happen during any event phase at all and there's no way to tell what that's going to be.
That's not really a big deal though- if you need more precise timing, just enqueue the delegate yourself and run it whenever you like.
Answer by Prastiwar · Dec 30, 2017 at 04:48 PM
Invoke always executes after you execute it. It's that simple. Invoke is totally different than these Unity event functions. It's like calling method by name exampleMethod();
vs Invoke("exampleMethod", 5);
.
I believe he is asking at what point in the execution order would example$$anonymous$$ethod be called. For example, in the frame 5 seconds later, would it be called before or after update?
As I said Invoke is totally different. Unity event functions are like hmm.. body of script. It has his Awake, Start and Update which run in specific frames of script's life and there is no much dependency between Awake/Update function and your invokes. I mean these function are like background for your Invoke. $$anonymous$$aybe I'm not clear, so let's play around in Unity and do a little test like below.
In this case, example method will execute before Update (and after Start) because Invoke doesn't execute it in specific frames, it'll invoke after 1s in this case, so a lot frames after Update. I had fun with ti$$anonymous$$gs, do I put float number "0.0000000000000000000000000000000000000000000001f"
- then it executes before Update.
bool message = false;
void Awake()
{
Invoke("example$$anonymous$$ethod", 1);
}
void Start()
{
Debug.Log("Start");
}
void Update()
{
if (!message)
{
message = true;
Debug.Log("Update");
}
}
void example$$anonymous$$ethod()
{
Debug.Log("Example");
}
Your answer
Follow this Question
Related Questions
Is there a way to set a GUI.matrix that will be used by all OnGui() functions? 1 Answer
Awake/Start order across different platforms. 3 Answers
How to implement "PreUpdate" function 4 Answers
How to move child with parent within the same frame. (Before trigger events) 2 Answers
Skip Awake/Start 1 Answer