Skip to reading
GDScript Programming & Godot

35. Startup order and script lifetime

Edition 0.86.4.1 HF1

0.86.4.1 Hotfix 1 edition. Earlier lessons and screenshots retain their original version context; revised references and supplements describe the newer behavior.

Download PDFView PDF page
Source table from 35. Startup order and script lifetime, page 44
HookWhat is available
_initThe instance is being constructed; no PCA runtime binding yet.
_enter_tree / _readyGodot tree lifecycle. PCA adds the node before binding Runtime and record proxies.
on_global_readyPCA’s deferred startup hook after binding a global record.
run / on_* eventPCA has refreshed caller context for that routed call.
_process / _physics_processOnly while the instance exists and processing is active.
_exit_treeCleanup as the instance leaves the tree.
Code example
var ready_before_binding: bool = false
Code example
func _ready() -> void:
    ready_before_binding = Runtime == null
Code example
func run() -> bool:
    return ready_before_binding

Put PCA-dependent startup work in on_global_ready or a routed function/event. Pure local initialization can happen in _init/_ready. If you are creating something inside the current room, wait for the relevant room-load event or a direct call after the room exists.

A temporary record is queued for deletion after the awaited call completes. A Timer added to it cannot keep a repeating job alive after the function returns. For a long-lived controller, use the global checkbox and deliberate cleanup. Editing/invalidation can replace that instance.

Page 44 of 378Permalink
Go to page