@onready
2023. 11. 24. 18:00
https://www.reddit.com/r/godot/comments/c62psf/i_do_not_know_what_the_meaning_of_onready_do_you/
var my_label
func _ready():
my_label = get_node("MyLabel")
#same as above
@onready var my_label = get_node("MyLabel")
standard variables are initialized when object is created, onready variables are initialized after the object is added to the scene tree.
Performance-wise, it's also good practice to cache get_node() calls by assigning them to a variable. Doing so in an onready member variable makes it easy to access the cached result from any function in the script.
'Godot4' 카테고리의 다른 글
CollisionObject2D (0) | 2023.11.24 |
---|---|
Getter Setter in Godot (0) | 2023.11.24 |
String (0) | 2023.11.24 |
고도엔진과 Your first 2D game (0) | 2023.11.23 |
GDScript (0) | 2023.11.23 |