Skip to content
Tutorials Center
My learning

Topics

Lesson 14 of 36 ยท GDScript

Godot Node Lifecycle: _ready, _process, _physics_process

Learn the Godot node lifecycle: _init, _enter_tree, _ready, _process, _physics_process, delta time, fixed timesteps, set_process, pausing and exit, with a runnable game-loop model.

A Godot game is a loop. Every frame the engine checks input, runs your scripts, simulates physics and draws the screen. Your code does not drive that loop. Instead, you override callback functions that the engine calls at specific moments. Knowing the order and meaning of these callbacks is the difference between code that works and code that crashes with null instances or jitters on fast computers.

Godot only runs in the editor, so GDScript here is read-only. The Python stand-in builds a miniature main loop with the same callback names, so you can watch the order and the effect of fixed versus variable timesteps.

The callbacks, in order

Callback When it runs Typical use
_init() The object is created (.new()), before it is in the tree Set simple defaults
_enter_tree() The node enters the scene tree (parent first) Rarely needed; register something
_ready() Node and all its children are in the tree; once per entry (children first) Get nodes, connect signals, set up
_process(delta) Every rendered frame Visuals, animation, UI, input polling
_physics_process(delta) Every physics tick (60 per second by default) Movement and physics
_input(event) / _unhandled_input(event) When an input event arrives Key presses, clicks
_exit_tree() The node is leaving the tree Clean up
GDSCRIPT
extends Node

func _init() -> void:
    print("init")

func _enter_tree() -> void:
    print("enter tree")

func _ready() -> void:
    print("ready")

func _process(delta: float) -> void:
    pass

func _physics_process(delta: float) -> void:
    pass

func _exit_tree() -> void:
    print("exit tree")

Output for a node added at startup is init, enter tree, ready. Note that _ready is called only once unless the node leaves and re-enters the tree (when request_ready() can trigger it again).

Remember the traversal rule from Scenes and the Scene Tree: _ready goes children first; _process goes parents first.

_process versus _physics_process

_process(delta) runs once per rendered frame. Frame rate varies (30, 60, 144 fps, or stuttering), so delta varies too. Use it for things that are visual or do not need exactness: updating a label, rotating decoration, polling input for UI.

_physics_process(delta) runs at a fixed rate (Project Settings > Physics > Common > Physics Ticks per Second, default 60). delta is constant (about 0.01667). Use it for anything involving bodies and collisions: move_and_slide(), applying forces, ray casts. A fixed step makes physics deterministic, so a jump has the same height at any frame rate. If the game runs slower than the tick rate, Godot runs several physics ticks per frame to catch up; if it runs faster, some frames have none.

Rule of thumb: movement of physics bodies goes in _physics_process; everything else in _process. Mixing them, for instance moving a CharacterBody2D in _process, produces jitter.

GDSCRIPT
extends CharacterBody2D

const SPEED := 250.0

func _physics_process(_delta: float) -> void:
    var dir := Input.get_vector("left", "right", "up", "down")
    velocity = dir * SPEED
    move_and_slide()          # uses delta internally, no need to multiply

Note: for move_and_slide() you set velocity in pixels per second and the method applies delta itself. For manual position changes (position += velocity * delta) you must multiply by delta. An underscore prefix (_delta) tells the editor you deliberately do not use the parameter and silences the unused warning.

Delta time done right

delta is the time in seconds since the previous call. Anything per-second must be multiplied by it:

GDSCRIPT
position.x += speed * delta                 # pixels per second
rotation += TAU * 0.25 * delta              # a quarter turn per second
cooldown -= delta                           # timers

Do not multiply instantaneous changes (a jump impulse, setting a velocity) by delta, and do not multiply velocity before move_and_slide().

Switching callbacks on and off

You can disable per-frame callbacks to save work:

GDSCRIPT
func _ready() -> void:
    set_process(false)           # stop calling _process
    set_physics_process(false)
    set_process_input(false)

func wake_up() -> void:
    set_process(true)

A node that has nothing to do each frame (a door, a pickup) should not waste a _process call. The process_mode property controls behavior while the game is paused: Inherit, Pausable (default), When Paused, Always or Disabled. A pause menu usually sets process_mode = Node.PROCESS_MODE_ALWAYS so it keeps working when get_tree().paused = true.

await and frames

Not everything must be a per-frame check. You can pause a function until something happens:

GDSCRIPT
func flash() -> void:
    modulate = Color.RED
    await get_tree().create_timer(0.2).timeout   # wait 0.2 s without blocking the game
    modulate = Color.WHITE

func _ready() -> void:
    await get_tree().process_frame               # wait for one frame

await suspends only this function; the game keeps running. We use it with signals in Signals.

A loop in the shape of a diagram

flowchart TD
    A["Start of frame"] --> B["Handle input events: _input"]
    B --> C["0 or more physics ticks: _physics_process"]
    C --> D["_process"]
    D --> E["Draw the frame"]
    E --> A

Input, then physics (fixed step, possibly repeated), then process, then render.

Stand-in: a tiny main loop in Python

This is not Godot: a simulation of the loop with a fixed physics step. At a low frame rate the physics function runs several times per frame, and at a high rate it sometimes does not run.

Python Stand-in (Python): fixed physics ticks inside variable frames

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Every row ends with 60 physics calls for one second and with process_time near 1.00s: physics is steady while _process follows the frame rate.

Common mistakes

  • Using $Child in _init (the node is not in the tree, so children do not exist).
  • Moving a physics body in _process.
  • Multiplying velocity by delta before move_and_slide().
  • Forgetting super() in an overridden _ready when the parent class has setup.
  • Doing heavy work every frame instead of on an event or timer.
  • Calling get_node in _process every frame. Cache nodes in @onready variables.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which callback is best for moving a CharacterBody2D?

    Physics bodies should move in _physics_process, which runs at a fixed rate.
  2. 2. What is the default number of physics ticks per second?

    The default is 60 physics ticks per second, independent of the render frame rate.
  3. 3. When is _ready called relative to the node's children?

    Children are ready first, so a parent can safely use them in _ready.
  4. 4. How can you wait 0.5 seconds without freezing the game?

    await suspends only the current function while the game continues.

Summary

  • Lifecycle: _init, _enter_tree, _ready (once, children first), then _process and _physics_process repeatedly, then _exit_tree.
  • _process follows the frame rate; _physics_process runs on a fixed tick (default 60/s).
  • Multiply per-second changes by delta; do not multiply a velocity given to move_and_slide().
  • Turn callbacks off with set_process(false) when idle; use process_mode for pause behavior.
  • await waits for timers or signals without blocking.

Next: Signals: Telling Other Nodes What Happened