give back children removed

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

I have deleted all the children of the node, how do I add them again?

 func _physics_process(delta):
    	if Input.is_action_just_pressed("ui_accept"):
    		for i in get_children():
    			remove_child(i)
    	if Input.is_action_just_pressed("ui_cancel"):
    		for i in get_children():
    			add_child(i)

this code makes that when pressing a key I delete them and when pressing another attempt they return but it does not work

:bust_in_silhouette: Reply From: mdubaisi
var childrens = []
func _ready():
  for i in get_children():
	 childrens.append(i)
func _physics_process(_delta):
   if Input.is_action_just_pressed("ui_accept"):
	 for i in childrens:
		 if i.is_inside_tree():
			 remove_child(i)
   if Input.is_action_just_pressed("ui_cancel"):
	     if get_child_count() == 0:
		     for i in childrens:
			    add_child(i)

I found that this script returns some errors tho.

:bust_in_silhouette: Reply From: Omicron

move/save children nodes to somewhere else, so you can reuse/readd them later