Skip to content

Game Loop

The core execution pattern of games that maintains a stable input-update-render loop.

  • When implementing a fixed-step simulation.
  • When input timing and render timing should be separated.
  • Input Step
  • Simulate Step
  • Render Step

The code below is a simplified Unity example based on the scenario described above.

using UnityEngine;
public sealed class FixedStepLoop : MonoBehaviour
{
private const float SimulationStep = 1f / 60f;
private float accumulatedDeltaTime;
private void Update()
{
accumulatedDeltaTime += Time.deltaTime;
while (accumulatedDeltaTime >= SimulationStep)
{
Simulate(SimulationStep);
accumulatedDeltaTime -= SimulationStep;
}
float interpolationAlpha = accumulatedDeltaTime / SimulationStep;
Render(interpolationAlpha);
}
private void Simulate(float deltaTime) { }
private void Render(float interpolationAlpha) { }
}
  • A fixed update order improves simulation reproducibility and makes debugging safer.
  • Separating fixed-step updates from interpolation helps balance physics accuracy and visual smoothness.
  • On heavy frames, the while loop can grow too long and lead to a spiral of death.
  • If responsibilities between Update and FixedUpdate are mixed, input latency and physics errors can increase.

This is the main loop that repeats input, simulation, and render on a frame basis.

Game Loop Flow