how to copy child to different parent

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Newby
:warning: Old Version Published before Godot 3 was released.

I made a scene and added already a lot of stuff to it but i realize i forgot my rigidbody2d and i can’t reparent a parent so i want to just move the children to my rigidbody2d but i dont know how
Pls help

:bust_in_silhouette: Reply From: avencherus

In the editor you can right click and Change Type for the parent’s Node type if that is easiest.

To move the children, just create the new parent node, select all the children and drag them into the new node. From there if you want that parent to be a root of the scene, you can right click and Save Branch as Scene.

If you’re talking about in code, you have to remove the child from the parent first, then add to the new parent.

Something like:

var parent = self
var child = get_node("child_to_move")

var new_parent = get_parent().get_node("new_parent")

parent.remove_child(child)
new_parent.add_child(child)