How to remove a node on ready via removechild?

Godot Version

4.2.1 stable

Question

i’m trying to remove the node “wands” via remove_child whenever the game starts so that i can call it later and make it appear back but using remove child just doesn’t remove it, using queue free does remove it but i don’t think i can call it later if use that

remove_child removes a child of the node that you call it on, so you need to call it on the parent of the node you want to remove. You can use get_parent() to get the parent, so try something like:

get_parent().remove_child(self)
1 Like

hey, thanks for the help
i added the get parent part so that it’s now func
_ready():
get_parent().remove_child(self)
but the node is still here when i launch the project

I tested it myself, and got this error message:

E 0:00:01:0340 TestRemove.gd:6 @ _ready(): Parent node is busy adding/removing children, remove_child() can’t be called at this time. Consider using remove_child.call_deferred(child) instead.

So I tried the suggested solution

get_parent().remove_child.call_deferred(self)

And that appears to work. What call_deferred does, as far as I understand it, is wait until there’s some idle time (in between frames and such), and call the function then.

thanks that worked !

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.