Game Development Reference
In-Depth Information
FixedUpdate : Like Update , this event is typically called multiple times per
frame. However, its calling pattern is regular and normalized, with fixed
time intervals between each call. The most common use of FixedUpdate is
to work with Unity physics. If you need to update the velocity or properties
of a Rigidbody component over time, then FixedUpdate rather than Update
would be the place to do it.
LateUpdate : This is called on each frame, like Update . However,
LateUpdate is always called after Update and FixedUpdate . This means that
when LateUpdate is called, you can be sure that Update and FixedUpdate
have already been called for every object on the current frame. This makes
LateUpdate a useful place to update camera movement, especially third-
person cameras, ensuring that the camera always follows objects at their
latest positions on the current frame.
The details of Update , FixedUpdate and LateUpdate , in combination with the
concepts of time and FPS, have significant implications on how you should or
should not code your games when creating motion over time. Specifically, two
main guidelines emerge, and these are considered over the next two subsections.
Rule #1 - frames are precious
Frames should occur many times per second; if they don't, your game will look
laggy and broken. On each frame, an Update event is called once for every active
MonoBehaviour in the scene. This means the computational complexity (and
performance) of your scenes on each frame depends, in large measure, on what
you do inside Update events. More functionality demands more processing time
and workload, either for the CPU or GPU. For large scenes with many objects and
components, it would be easy then for things to get out of hand if you don't reduce
the workload inside Update functions by careful code planning. It's important,
therefore, to think of Update events or any regularly called frame-based events as
precious. In short, you should only put code inside them when you really need
to, such as to read player input or observe cursor movement. It's helpful to start
thinking of event-driven programming, as this can help you seriously reduce the
workload inserted inside Update functions. The next chapter considers event-driven
programming and event systems.
 
Search WWH ::




Custom Search