rawsp33d/gdext-v

Make onready work for nested onready fields

Open

#23 opened on Jun 2, 2025

View on GitHub
 (0 comments) (0 reactions) (0 assignees)V (1 fork)auto 404
enhancementhelp wanted

Repository metrics

Stars
 (15 stars)
PR merge metrics
 (PR metrics pending)

Description

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
	}
}

Contributor guide