An annotation is an extra piece of information or metadata included in code that provides the computer or the user with more information about how the code works.
In the GDScript language, annotations start with an @
sign and are used to change the behavior of the following code statement.
For example, the @onready
annotation makes the initialization of a member variable run right before the _ready()
function. And the @export
annotation and its many variants make a property editable in the Inspector dock in the editor.
@onready var label: Label = $Label
Is nearly equivalent to the following:
var label: Label = null
func _ready() -> void:
label = $Label
The nuance is that the @onready
annotation makes the initialization of the label
variable run right before the _ready()
function. In practice, it's the same as inserting the initialization code at the beginning of the _ready()
function.