Can't add child '…' to '…', already has a parent '…' in Godot 4
By Eduardo Orellana · Updated
A node has one parent, and this one already has it. b.add_child(c) after a.add_child(c) prints Can't add child 'Coin' to 'Shelf', already has a parent 'Bag'. and leaves it where it was. Move it with c.reparent(b), or remove it from its parent first.
AppImage, x86_64. Ubuntu 22.04, Debian 12, Fedora 39 or newer.
Intel or AMD Chromebook, with Linux turned on.
What Godot is checking
Node::add_child() refuses a node whose parent is set, prints this error with the three names, and returns. The script carries on, and the node stays under its first parent.
reparent() removes the node from its parent and adds it to the new one in one call, and by default keeps its global transform.
Reproduce it
A coin added to a bag, then added to a shelf.
extends Node
func _ready() -> void:
var bag := Node.new()
bag.name = "Bag"
var shelf := Node.new()
shelf.name = "Shelf"
add_child(bag)
add_child(shelf)
var coin := Node.new()
coin.name = "Coin"
bag.add_child(coin)
shelf.add_child(coin)
print("coin is under ", coin.get_parent().name)
What Godot 4.7.2 prints
Godot Engine v4.7.2.stable.mono.official.ed1daf0bf - https://godotengine.org
ERROR: Can't add child 'Coin' to 'Shelf', already has a parent 'Bag'.
at: add_child (scene/main/node.cpp:1717)
GDScript backtrace (most recent call first):
[0] _ready (res://answers/cant-add-child-already-has-a-parent/repro.gd:13)
coin is under BagFix it
Move it with reparent().
extends Node
func _ready() -> void:
var bag := Node.new()
bag.name = "Bag"
var shelf := Node.new()
shelf.name = "Shelf"
add_child(bag)
add_child(shelf)
var coin := Node.new()
coin.name = "Coin"
bag.add_child(coin)
coin.reparent(shelf)
print("coin is under ", coin.get_parent().name)
What the fixed script prints
Godot Engine v4.7.2.stable.mono.official.ed1daf0bf - https://godotengine.org
coin is under ShelfAdding the same instance twice in a loop
Instantiating once outside a loop and calling add_child() inside it adds the first copy and refuses the rest. Call instantiate() inside the loop so each pass makes a new node.
for i in 5:
var enemy := enemy_scene.instantiate()
add_child(enemy)
Verified on Godot 4.7.2
Both scripts on this page were run headless on Godot 4.7.2 (4.7.2.stable.mono.official.ed1daf0bf) on 18 October 2026, and the output above is what Godot printed, unedited.
Where the check lives in Godot's source: [node.cpp line 1717, the message](https://github.com/godotengine/godot/blob/4.7.2-stable/scene/main/node.cpp#L1717), [Node.reparent in the class reference](https://github.com/godotengine/godot/blob/4.7.2-stable/doc/classes/Node.xml).
Questions
- What does remove_child() do to the node?
- It takes it out of the tree without freeing it. Add it somewhere else, or free it, or it leaks.
- Does reparent() keep the position?
- Yes, by default it keeps the global transform. Pass false as the second argument to keep the local one.
Related
- Parent node is busy setting up children, add_child() failed
- Node not found: "…" (relative to "…")
- Every verified Godot 4 answer
- How to get the class name of a node in Godot 4: get_class() and get_global_name()
- Invalid call. Nonexistent function 'instance' in base 'PackedScene' in Godot 4
- Cannot get return value of call to "…()" because it returns "void" in Godot 4
- Trying to cast a freed object in Godot 4
- How to change scenes in Godot 4: change_scene_to_file()
Flockbay's agent reads Godot's debugger output and fixes errors like this one in your project, on the official Godot.
Download Flockbay free