- Home /
Another Question about Execution Order
Let's say there are scripts a and b.
Is the order:
a Update -> b Update -> a LateUpdate -> b LateUpdate
or
a Update -> a LateUpdate -> b Update -> b LateUpdate?
LateUpdate wouldn't be nearly as useful if ir worked like example B. It 100% works like example A. The most common use for LateUpdate is for camera movement, so that all other objects updated before you move the camera.
Answer by hollums · Feb 17, 2019 at 02:29 AM
To my understanding of Execution Order of Event Functions, Update is fired first across all MonoBehaviours, then LateUpdate passes across them. So the first line you typed is the correct interpretation.
a Update -> b Update -> a LateUpdate -> b LateUpdate
I did an experiment for this to confirm: I created ScriptA and ScriptB, which are mostly clones of one another, with exception to what they log to the console. The result is in an image I've attached.
public class ScriptA : MonoBehaviour {
bool loggedUpdate = false;
bool loggedLate = false;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (!loggedUpdate)
{
Debug.Log("A UPDATE");
loggedUpdate = true;
}
}
void LateUpdate()
{
if (!loggedLate)
{
Debug.Log ("A LATE");
loggedLate = true;
}
}
}
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