Node Lifecycle Callbacks
For the close request to be handled manually, set get_tree().auto_accept_quit = false.
16.1 The main callbacks
Initialize plain variables Node added to the tree (parents before children) Register with managers
Node and all children are in the tree (children before parents); once per node lifetime Get node refs, connect signals, setup Every rendered frame Visuals, UI, non-physics logic Every physics tick (60 Hz default) Movement, physics Every input event Global input that should always fire After GUI, for shortcuts Unhandled key events Input not consumed by UI or _input Node about to leave the tree Cleanup, unregister
Low-level events (window close, predelete, pause) When a CanvasItem is redrawn Custom 2D drawing (queue_redraw())
16.2 Order of execution
For the close request to be handled manually, set get_tree().auto_accept_quit = false.
Scene loaded:
_init (each node)
_enter_tree: Root → Child A → GrandChild → Child B (top-down)
_ready: GrandChild → Child A → Child B → Root (bottom-up)
Every frame: _process (tree order); every physics tick: _physics_process
Removed: _exit_tree: children first, then the parent (bottom-up); then the node is freed (queue_free) or kept (remove_child)extends Node
func _init() -> void: print("init")
func _enter_tree() -> void: print("enter tree")
func _ready() -> void: print("ready")
func _exit_tree() -> void: print("exit tree")
func _notification(what: int) -> void:
match what:
NOTIFICATION_WM_CLOSE_REQUEST:
save_game()
get_tree().quit()
NOTIFICATION_PREDELETE:
print("about to be freed")
NOTIFICATION_APPLICATION_PAUSED:
print("app went to background (mobile)")16.3 Controlling processing
Behavior when SceneTree.paused is true Same as parent (default) Stops when paused Runs only when paused (pause menus)
set_process(false) # stop _process
set_physics_process(false)
set_process_input(false)
set_process_unhandled_input(false)
process_mode = Node.PROCESS_MODE_ALWAYS # keep running when the tree is paused
process_priority = -1 # lower runs earlier
get_tree().paused = true # pause the game (nodes with PROCESS_MODE_INHERIT/PAUSABLE stop)16.4 _process vs _physics_process
_physics_process runs at a fixed rate (*Project Settings → Physics → Common → Physics Ticks per Second*); use it for anything touching physics bodies.
_process runs as often as frames render (variable delta).
Enable physics interpolation (*Physics → Common → Physics Interpolation*, 2D in 4.3+, 3D in 4.4+) to get smooth visuals at low tick rates.
16.5 Custom drawing
Godot 3 note: update() became queue_redraw().
extends Node2D
var radius := 50.0:
set(v):
radius = v
queue_redraw()
func _draw() -> void:
draw_circle(Vector2.ZERO, radius, Color.ORANGE)
draw_line(Vector2.ZERO, Vector2(radius, 0), Color.BLACK, 2.0)
draw_rect(Rect2(-10, -10, 20, 20), Color.RED, false, 1.0)
draw_string(ThemeDB.fallback_font, Vector2(0, -60), "Hello", HORIZONTAL_ALIGNMENT_CENTER)