Right now @[gd.onready] works for fields that are predefined Godot types, and it also works for custom structs. However it does not properly initialize the onready fields on those types. This is really only relevant for custom classes.
IE if you have this:
struct Main {
gd.Node
mut:
death_sound gd.AudioStreamPlayer @[gd.onready]
hud HUD @[gd.onready]
}
struct HUD {
gd.CanvasLayer
mut:
start_button gd.Button @[gd.onready:]
}
The Main instance will indeed have instance.hud set on ready, but instance.hud.start_button will be empty.
To work around this for now you can just remove the onready from custom structs, and initialize them manually in ready_ of the parent:
fn (mut s Main) ready_() {
// TEMP: workaround onready not working great with nested onready nodes
node := s.get_node_v('hud')
if mut hud := node.try_cast_to_v[HUD]() {
s.hud = hud
}
}
Right now
@[gd.onready]works for fields that are predefined Godot types, and it also works for custom structs. However it does not properly initialize the onready fields on those types. This is really only relevant for custom classes.IE if you have this:
The
Maininstance will indeed haveinstance.hudset on ready, butinstance.hud.start_buttonwill be empty.To work around this for now you can just remove the
onreadyfrom custom structs, and initialize them manually inready_of the parent: