Skip to content

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.

Download for macOSDownload for WindowsDownload for Linux

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.

GDScript
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

Output
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 Bag

Fix it

Move it with reparent().

GDScript
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

Output
Godot Engine v4.7.2.stable.mono.official.ed1daf0bf - https://godotengine.org

coin is under Shelf

Run this fix with your agent

Flockbay is the Godot editor with an AI agent built in. Paste this into Flockbay's chat, or into Claude Code or Codex connected to Flockbay over MCP: the agent finds the cause in your project, applies the fix, runs the game headless and reads Godot's output to check it.

More on this: GameMaker to Godot: rebuild your GML game in Godot 4

Prompt
My Godot 4 project prints this error: "Can't add child 'Coin' to 'Shelf', already has a parent 'Bag'.". Find where it comes from and fix it. 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. Then run the game headless and check that Godot's output no longer shows it.

Adding 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.

More on this: Can't change this state while flushing queries. Use call_deferred() or set_deferred() to change monitoring state instead in Godot 4

GDScript
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, Node.reparent in the class reference.

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.

Flockbay's agent reads Godot's debugger output and fixes errors like this one in your project, on the official Godot.

Download Flockbay free