This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
+1 vote

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

Godot version 3.2
in Engine by (196 points)
edited by

2 Answers

0 votes
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.

by (290 points)
0 votes

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

by (340 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.