Reverse a remove child

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Acidmoss

How would one add a node back into the tree after it has been removed with something like queue_free or remove_child?

:bust_in_silhouette: Reply From: wombatstampede

A node which is freed with queue_free() is no more. There’s no zombie virus that’d bring that back. But you could create & set & add_child() a totally new instance of that node class if that makes sense. (Or load it from a scene)

remove_child() (Called by the parent of that node) usually is the method of choice to remove a node temporarily from the tree. And adding that node back to the tree is simply done by calling add_child() from some parent node where you want it to hook in.

The docs have a little code sample that demonstrates unlinking a node and adding it again to another node:

I think I’ve come across a caveat with remove_child(). Using change_scene() appears to cause my node hidden with remove_child() to be freed.

blurrred | 2022-10-20 18:09