IceBergyn The point is that the error message tells you exactly what is happening and why. It even suggests how to "fix" it. So it's important to read and understand error messages.
The "probelm" will happen with every type of node if you try to add children before the parent node has been fully set up upon run. The node is fully set up when all of its children (as set in the editor) are fully set up. This won't be true if you try to add a child to a parent from the _ready()
callback of one of its children. At this point the _ready()
of the parent as well as some of the children (depending on the order) have not been executed yet, so the initialization of children is still ongoing, hence "the node is busy setting up children". Using call_deferred()
postpones this to immediately after the whole tree has been initialized.
You can also "fix" it without call_deffered()
by running the duplication code in the _ready()
callback in a script attached to the parent (instead of a child), because parent's _ready()
is called immediately after all children have been set up.
This whole thing is a consequence of Godot's architecture, i.e. storing scene graphs as trees, which results in a strict hierarchical order of node initialization and script execution.