A var
is assigned a value when the script instance is created. At this point the node may not be ready on the scene (ex: you called instance() but not add_child) For that reason, you can set a default value to it that will be set only once, but it can't be an expression related to the tree (like get_node
or get_parent
).
An onready var
is assigned a value after the node and its siblings entered the tree. It's a shortcut for assigning variables in _ready()
, also note that _ready()
is also called when the node leaves and re-enter the tree again. Because of this initialization order, onready
lets you assign values that depend on the tree you are instanced in, so you can use get_node
with it.
The keyword is explained in the doc: http://docs.godotengine.org/en/latest/reference/gdscript.html?highlight=onready
Note: using onready
on scripts that are not extending Node (or derived) is kinda pointless^^"