Godot Version
v4.3.stable.mono.official [77dcf97d8]
Question
I have some code that looks like this, for a Control node that I want to populate with children loaded from a saved scene. To maintain the correct layout it is important that the children of the scene root node are added as children, rather than the root node itself being added as a child.
@tool
class_name MyControl extends Container
const _init_scene_preload := preload("./MyScene.tscn")
func _init() -> void: # Same errors if placed instead in _ready
self._init_scene()
func _init_scene() -> void:
var scene_root_node := _init_scene_preload.instantiate()
for child: Node in scene_root_node.get_children():
child.reparent(self)
Using this approach, my console is full of warnings (first line) and errors (second line) like this in the editor:
scene/main/node.cpp:1579 - Adding 'NameLabel' as child to '' will make owner 'MySceneRootNode' inconsistent. Consider unsetting the owner beforehand.
scene/main/node.cpp:2518 - Condition "!is_ancestor_of(p_node)" is true. Returning: false
I have also received the same or similar errors when using different combinations of remove_child, set_owner, and add_child.
These warnings and errors do not seem to affect the functionality of the custom Control, but the spam in the console is inconvenient and makes me wonder if there is a problem with the behavior that I just haven’t noticed yet.
How can I handle this without the console being spammed with warnings and errors?