Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When is the best time to update the Unity Camera?

Tags:

unity3d

Sorry to ask such as simple question, but my friend and I were discussing when is the best time to move the camera in a Unity3d game.
Basically discussing whether we should move it on an Update, FixedUpdate, or LateUpdate.

I believe LateUpdate would be the best time to move the camera to ensure that all other calculations are done first. But he says you should do it during update and just set it to be the last thing that updates.

Can I get some feedback on either of these and why one may be better than the other?

like image 664
Subwolfer Avatar asked Jan 26 '23 02:01

Subwolfer


1 Answers

From the Unity docs:

LateUpdate is called after all Update functions have been called. This is useful to order script execution. For example a follow camera should always be implemented in LateUpdate because it tracks objects that might have moved inside Update.

This makes it sound like semantically there is no difference between LateUpdate() and making the camera update be the last statement in Update(). However, using LastUpdate() emphasizes that there is special significance to having the camera be updated at the end of the frame. This makes it less likely that someone in the future might accidentally add code later that would get executed after the camera update.

like image 55
jbinvnt Avatar answered Jan 29 '23 11:01

jbinvnt