What is the difference between Update() , LateUpdate() , FixedUpdate(), and when i should use them
Update() , LateUpdate() and FixedUpdate()
what is the difference between these and when i should use one of them and is it wrong to use Update() all the time?
Answer by Meltdown · Aug 05, 2011 at 05:10 AM
Check out this link on Update Order
but.... can i have example about when i should use one of them :)
Generally, you will use Update for most operations. Such as changing transforms, or rotating items. FixedUpdate is usually used when you are calculating physics, such as applying forces to a rigidbody. i.e rigidbody.AddForce() etc. Anything that does calculations on the physcs side of things is usually used in FixedUpdate. In most other cases you will use Update().
I suppose this page was replaced by this one: http://docs.unity3d.com/Documentation/$$anonymous$$anual/ExecutionOrder.html
Answer by GizmoKaracho · Aug 30, 2017 at 10:13 AM
- Update() is called on every Frame, regardless of time passed since last frame
Good for Movement, InputControl etc. (most of the time you'll use Update)
Usually you will use Time.DeltaTime to take passed time into account (e.g. for GameObject Translations)
- LateUpdate() is called after all Update() methods are processed
So e.g. for the camera that follows your character it's good to Update after it has moved
FixedUpdate() is called by the physics engine in fixed intervals (that can be set in the Options)
This is basically good for all Physics related functions (trigger, collisions etc.)
Answer by mdforbes500 · Aug 11, 2017 at 06:48 AM
Don't forget, @Ziad , that if you are performing camera scripting its best to put it in LateUpdate(). That way the movement calculations have already been done.
I have in a LateUpdate function:
if(!thisVariable)
thisVariable = GetComponent<Component>();
Originally I had it in a Start() function but sometimes it wasn't setting itself which is why I set it here.
Is that okay for performance?
Since thisVariable is initialized only once (that's the so-called "lazy initialization"), the impact on the performance is negligible - just an if instruction that evaluates false every frame but the first one.
Your answer
Follow this Question
Related Questions
How can I make my cursor to follow more faster? (there's too much delay) 0 Answers
Only Disable One Update on a Script 1 Answer
Score, FixedUpdate and Update 0 Answers
How to handle FixedUpdate() and Input 0 Answers
Addforce in fixedupate 0 Answers