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 a 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:

More...
struct Node
@nogc nothrow
void
addChild
(,
in bool legible_unique_name = false
)

Detailed Description

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/3.2/tutorials/misc/running_code_in_the_editor.htmltool scripts/url and url=https://godot.readthedocs.io/en/latest/tutorials/plugins/editor/index.htmleditor 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.

Meta