Calling order (_ready(), onready var, const, var, export var)

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Felipe

When I am initialising a script, what is the call order of this:
_ready(),
onready var,
const,
var,
export var
?
All of this are in the same script. Ignoring the fact that may or not have a child node.
Thank you!

:bust_in_silhouette: Reply From: njamster

What do you mean? Variables and constants aren’t called, so there isn’t a call order either. All of them will be available when _ready is called.

which one is called first onready var or ready

supper_raptor | 2020-05-20 07:42

onready var. It’s easy to check for yourself:

onready var variable = "test"

func _init():
	print("INIT:  ", variable)

func _ready():
	print("READY: ", variable)

njamster | 2020-05-20 08:39

:bust_in_silhouette: Reply From: Ertain

From what I can tell, onready var is called when the node to which it is referring is instantiated, and it enters the node tree. The export var code is a bit trickier. If the user doesn’t have any value assigned to the exported variable in an _init() function, and the node isn’t being instanced, then it’ll receive the initial value defined in the script. So it may go something like this:

(export var) -> (onready var) -> ( _ready() ) -> (var/const, depending on which one was called first in the script)

For more information, look on the Godot Notifications article for more details.