FixedUpdate and Update are two ways Unity runs code repeatedly. They help control when and how often your game actions happen.
FixedUpdate vs Update in Unity
Introduction
Syntax
Unity
void Update() {
// code runs every frame
}
void FixedUpdate() {
// code runs at fixed time intervals
}Update runs once every frame, which can vary in time depending on the device.
FixedUpdate runs at a steady, fixed time step, good for physics calculations.
Examples
Unity
void Update() {
if (Input.GetKeyDown(KeyCode.Space)) {
Debug.Log("Jump pressed");
}
}Unity
void FixedUpdate() {
Rigidbody rb = GetComponent<Rigidbody>();
rb.AddForce(Vector3.up * 10);
}Sample Program
This script moves an object forward smoothly using FixedUpdate and logs when the W key is pressed using Update.
Unity
using UnityEngine; public class MoveObject : MonoBehaviour { Rigidbody rb; void Start() { rb = GetComponent<Rigidbody>(); } void Update() { if (Input.GetKeyDown(KeyCode.W)) { Debug.Log("W key pressed"); } } void FixedUpdate() { rb.MovePosition(rb.position + Vector3.forward * 0.1f); } }
Important Notes
Update frequency depends on frame rate, so it can be uneven.
FixedUpdate runs at consistent intervals, making it better for physics.
Never put physics code in Update to avoid jittery movement.
Summary
Update is for frame-based actions like input and animations.
FixedUpdate is for physics and smooth movement at fixed time steps.
Use each one where it fits best to keep your game running smoothly.
Practice
1. What is the main difference between
Update and FixedUpdate in Unity?easy
Solution
Step 1: Understand the timing of
UpdateUpdateis called once per frame, so its timing depends on the frame rate.Step 2: Understand the timing of
FixedUpdateFixedUpdateis called at fixed intervals, independent of frame rate, ideal for physics calculations.Final Answer:
Updateruns every frame;FixedUpdateruns at fixed time intervals. -> Option BQuick Check:
Update = frame-based, FixedUpdate = fixed interval [OK]
Hint: Remember: Update = frame, FixedUpdate = fixed time [OK]
Common Mistakes:
- Confusing which method runs at fixed intervals
- Thinking FixedUpdate depends on frame rate
- Assuming Update is for physics only
2. Which of the following is the correct syntax to declare the
FixedUpdate method in a Unity C# script?easy
Solution
Step 1: Check method name capitalization
Unity requires exact method names with correct capitalization;FixedUpdatestarts with capital F and U.Step 2: Verify method signature
The method must be declared asvoid FixedUpdate()with no parameters.Final Answer:
void FixedUpdate() { /* code here */ } -> Option AQuick Check:
Correct capitalization and signature = void FixedUpdate() { /* code here */ } [OK]
Hint: Method names are case-sensitive; use exact spelling [OK]
Common Mistakes:
- Using wrong capitalization like fixedUpdate
- Adding underscores in method names
- Adding parameters to FixedUpdate
3. Consider this Unity C# script snippet:
void Update() {
Debug.Log("Update called");
}
void FixedUpdate() {
Debug.Log("FixedUpdate called");
}
If the game runs at 60 frames per second and the fixed timestep is 0.02 seconds, which output will appear more frequently in the console?medium
Solution
Step 1: Calculate Update calls per second
At 60 FPS,Updateruns 60 times per second.Step 2: Calculate FixedUpdate calls per second
Fixed timestep is 0.02 seconds, soFixedUpdateruns 1/0.02 = 50 times per second.Final Answer:
"Update called" will appear more frequently. -> Option CQuick Check:
60 (Update) > 50 (FixedUpdate) calls per second [OK]
Hint: Update frequency = FPS; FixedUpdate frequency = 1/fixedDeltaTime [OK]
Common Mistakes:
- Assuming FixedUpdate runs more often than Update
- Ignoring fixed timestep value
- Confusing frame rate with fixed update rate
4. You wrote this code to move a Rigidbody smoothly:
void Update() {
rb.AddForce(Vector3.forward * forceAmount);
}
But the movement is jittery. What is the best fix?medium
Solution
Step 1: Identify physics update timing
Physics updates happen in fixed time steps, so applying forces inUpdatecauses inconsistent timing and jitter.Step 2: Move physics code to
CallingFixedUpdateAddForceinsideFixedUpdatematches physics timing and smooths movement.Final Answer:
Move theAddForcecall intoFixedUpdate. -> Option AQuick Check:
Physics code belongs in FixedUpdate [OK]
Hint: Put physics code in FixedUpdate to avoid jitter [OK]
Common Mistakes:
- Applying physics forces in Update
- Trying to fix jitter by increasing force
- Disabling physics instead of fixing timing
5. You want to create a smooth player movement that responds to input and uses physics. Which is the best way to organize your code?
hard
Solution
Step 1: Understand input timing
Input should be read every frame inUpdateto avoid missing user actions.Step 2: Understand physics timing
Physics forces should be applied inFixedUpdatefor consistent physics simulation.Step 3: Combine input and physics correctly
Store input values inUpdate, then use them inFixedUpdateto apply forces smoothly.Final Answer:
Read input inUpdate, apply movement forces inFixedUpdate. -> Option DQuick Check:
Input in Update + physics in FixedUpdate = smooth movement [OK]
Hint: Input in Update, physics in FixedUpdate for smooth control [OK]
Common Mistakes:
- Reading input in FixedUpdate causing missed inputs
- Applying physics in Update causing jitter
- Ignoring input or physics timing differences
Recommended
Ready to prove it?
Pass the test and this pattern moves unknown
10 questions ~5 mineasy hard
