About update, lateupdate, and fixedupdate in Unity

Source: Internet
Author: User

welcome here .Unity Learning,Unity Training,UnityEnterprise Training and education area, there are manyU3D Resources,U3D Training Video,U3d Tutorials,U3d Frequently Asked Questions,U3d Project Source Code, we are committed to building the industryUnity3dTraining, learning the first brand.

Monobehaviour.update Update

When Monobehaviour is enabled, its update is called at each frame.

Monobehaviour.fixedupdate Fixed Update

When Monobehaviour is enabled, its fixedupdate is called at each frame.

When handling rigidbody, you need to use fixedupdate instead of update. For example: When you add a force to a rigid body, you must apply a fixed frame in the fixedupdate instead of the frame in the update. (both frame lengths differ)

Monobehaviour.lateupdate later than update
When behaviour is enabled, its lateupdate is called at each frame.

Lateupdate is called after all the update function calls. This can be used to adjust the script execution order. For example: When an object moves in the update, the camera following the object can be implemented in the lateupdate.

The difference between update and fixedupdate:

The update is related to the number of frames on the current platform, while Fixedupdate is the real time, so when dealing with physical logic, put the code in fixedupdate instead of update.

Update is called every time a new frame is rendered, that is, the update frequency of the function is related to the performance of the device and the object being rendered (which can be thought of as the number of triangles). In the performance of the machine may be FPS 30, the difference may be smaller. This causes the same game to be inconsistent on different machines, some of which are fast and slow. Because the execution interval for update is different.

The Fixedupdate, which is performed at fixed intervals, is not affected by the game frame rate. Kinda want to tick. So it's best to use fixedupdate when dealing with rigidbody.

The ps:fixedupdate time interval can be changed in the project settings, Edit->project setting->time find the fixed timestep. You can modify it.

The difference between update and lateupdate

In the Holy Scriptures lateupdate is interpreted as a sentence: Lateupdate is called after all update function calls. This can be used to adjust the script execution order. For example: When an object moves in the update, the camera following the object can be implemented in the lateupdate. This sentence I read foggy, later read the explanation of others to understand come over.

Lateupdate is executed later than all update. For example: There are 2 steps in the game, footsteps 1 contains update and lateupdate, Footstep 2 contains update, then when the game executes, each frame is 2 footsteps in the update after the execution of the lateupdate. Although executed in the same frame, the update executes first and lateupdate is executed late.

Now suppose that there are 2 different scripts that control an object in the update, and when one of the scripts changes the orientation, rotation, or other parameters of the object, and the other footstep is changing these things, the orientation and rotation of the object will appear a certain amount of repetition. If there is another object that follows the object in the update to move and rotate, the object that follows will appear jittery. If it is followed in lateupdate, it will only follow the last position and rotation of all the update executions, thus preventing jitter.

To do a camera following the function of the protagonist, the camera's position adjustment is written in lateupdate (), always do not understand, look at the official Smoothfollow camera following written in Update ()


For more highlights, please click here .http://www.gopedu.com/

About update, lateupdate, and fixedupdate in Unity

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.