+1 vote

Hi,

I'm using remove_child as a form to stop a node to interac with others

The thing is that once it's previous parent gets removed by queue_free i want it to be removed as well

for now I am using addchild in _exittree

here what the code looks like:

onready var object = get_node('path')

func _ready():
    remove_child(object)

func _exit_tree():
    add_child(object)

I printed the object after that and seems like it is gone. But is it really gone?
If not, is there a way to remove it?

Thanks!

in Engine by (26 points)

2 Answers

+2 votes
Best answer

remove_child does indeed remove the child from its parent, but it does not delete the child. You seem to be calling add_child while the other node is getting removed/freed. Yeah I'd say that the node is really gone. But I'd use queue_free with that node instead.

by (3,910 points)
selected by

All rigth, thanks for the answer!

+1 vote

Hi,
As the docs. When calling queue_free on the parent, all children get deleted also

by (3,469 points)

But he removed said child from the scene tree. Making it a child no more. You'd have to either add it back as a child prior to tree exit, or manually call queue_free().

Yes. I'm simply calling object.queue_free now as you suggested
Seems to be working fine

You are right, if it's no more a child it wont get deleted. My bad.

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.