Function Node.addChild
Adds a child node. Nodes can have any number of children, but every child must have a unique name. Child nodes are automatically deleted when the parent node is deleted, so an entire scene can be removed by deleting its topmost node.
If legible_unique_name
is true
, the child node will have an human-readable name based on the name of the node being instanced instead of its type.
Note: If the child node already has a parent, the function will fail. Use removeChild
first to remove the node from its current parent. For example:
if child_node.get_parent(): child_node.get_parent().remove_child(child_node) add_child(child_node)
Note: If you want a child to be persisted to a PackedScene
, you must set owner
in addition to calling addChild
. This is typically relevant for url=https://godot.readthedocs.io/en/latest/tutorials/misc/running_code_in_the_editor.html
tool scripts/url
and url=https://godot.readthedocs.io/en/latest/tutorials/plugins/editor/index.html
editor plugins/url
. If addChild
is called without setting owner
, the newly added Node
will not be visible in the scene tree, though it will be visible in the 2D/3D view.