1

I can't understand the use case of the LateUpdate() here. If the LateUpdate() is called after the Update(), then what is the difference the below two set of codes:

First set of code

void Update(){
    <some code>
    <further code>
    a();
}
 
void a(){
    <some code for a>
}

Second set of code

void Update(){
    <some code>
    <further code>
}
 
void LateUpdate(){
    <some code for a>
}

Are both the codes above same or is there any difference/ benefits on using the LateUpdate() instead of just calling a method as the last statement of the update()?

1 Answer 1

3

LateUpdate is called after all Update functions have been called. So if you have 15 Scripts with an Update function, and one with LateUpdate -- LateUpdate in that one script won't execute until the other 15 Updates have been called. So the difference between your two examples is that in the first one, a() is run right away as part of that Update invocation. In the second, <some code for a> won't run until every script with an Update function has run.

Reference https://docs.unity3d.com/ScriptReference/MonoBehaviour.LateUpdate.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.