Godot Version
4.2.1
Question
I am adding a very simple variable, but Godot doesn’t recognize it. here’s the code, is this a bug, or am I missing something?
4.2.1
I am adding a very simple variable, but Godot doesn’t recognize it. here’s the code, is this a bug, or am I missing something?
The “onready” property works when the node is ready, so you must use it in a function to use the variable.
For example, you can use the variable like this:
func _ready() -> void:
sprite_2d.visible = false;
or
@onready var sprite_texture = sprite_2d.texture;
You can’t call functions , variables, etc from within the script’s body. You need to do it within a function.
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.