How do I wait for a child to "spawn in" before doing logic on the parent that concearns the child

Godot Version

4.6 Stable

Question

So I have some code to setup child mesh attributes, in this case just size, from the parent in the prefab. I also have a simple setter function to check for changes in editor, now this all works just fine but I get an absurd amount of errors when loading in the prefab and especially when changing the size value to the point where it lags out the editor completely its all one same error:
ERROR: scene/3d/node_3d.cpp:642 - Condition β€œ!is_inside_tree()” is true. Returning: Transform3D()

@tool
extends StaticBody3D

### House Variables
@export var house_size:Vector3 = Vector3(2.5, 2.0, 3.0):
	set(value):
		house_size = value
		init_house_mesh()

@onready var house_mesh_inst = $HouseMesh

# Called when the node enters the scene tree for the first time.
func _ready() -> void:
	init_house_mesh()


## Called to initialize the values of HouseMesh
func init_house_mesh() -> void:
	house_mesh_inst.mesh.size = house_size

This is the prefab structure
image
and these are the errors

Again the mesh does change shape and everything kind of works but I mean look at this, 10k errors for 0.5s of changing a value in the editor:

Any help would be greatly appreciated and thanks in advance!

Try this in your _ready method:

init_house_mesh.call_deferred()

That will make the call wait until the end of the frame.

Mind you, this is just a guess - but something seems to be making Godot think your mesh node isn’t in the tree.

@iOSxcOder - I think this is a really good example of a forum question.

4 Likes

Yeah, that seems to have worked, I am not sure exactly what is happening and it certainly does seem like this issue comes up in some other places, I will monitor this and see since I even saw errors regarding uniforms at times but that could be a completely different thing unrelated to this for this does the job properly thanks!