What is the difference between the Update
and FixedUpdate
methods, and when should these methods be used?
相关问题
- Unity - Get Random Color at Spawning
- Unity3D WebGL Headless not rendering
- Unity3D loading resources after build
- Load Image from Stream/StreamReader to Image OR Ra
- Unity3D - Build Failed because of “[Unity] ERROR:
相关文章
- Programmatically setting and saving the icon assoc
- Omnisharp in VS Code produces a lot of warnings ab
- Call non-static methods on custom Unity Android Pl
- How can a game created in Unity can run on an Andr
- How to add Persistent Listener to Button.onClick e
- Placing an object in front of the camera
- Connecting Unity3d Android application to ActiveMQ
- How to mimic HoloLens 2 hand tracking wIth Windows
FixedUpdate is used for being in-step with the physics engine, so anything that needs to be applied to a rigidbody should happen in FixedUpdate. Update, on the other hand, works independantly of the physics engine. This can be benificial if a user's framerate were to drop but you need a certain calculation to keep executing, like if you were updating a chat or voip client, you would want regular old update.
Unity has a nice video about Update vs. FixedUpdate here: Unity - Update vs. FixedUpdate
The site is a great resource for beginner game programmers.
Adding to the other answers, Update is in time with the frame rate, not the physics calculation rate. This means that usually when something changes visuals, you want to have it done in Update, not FixedUpdate. This ensures it's always in time for the very moment at which the frame is rendered. I've encountered a number of cases where I had movement that didn't look smooth because I had it calculated in FixedUpdate.
The only potential cost to having something done in Update that should be done in FixedUpdate is that your physics fidelity could drop, especially if you're hitting low frame rates (but in general that's a separate problem that should be fixed, so it's usually not a good reason to put something in FixedUpdate instead of Update).
If you're looking to control the order in which different scripts do their Updates, FixedUpdate is the wrong tree to bark up; you should be looking at something like EarlyUpdate instead.
From the forum:
Also refer to the answer given by duck in the same forum for a detailed explanation of the difference between the two.