Is my node freed?

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

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 add_child in _exit_tree

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!

:bust_in_silhouette: Reply From: p7f

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

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().

SIsilicon | 2018-12-06 02:18

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

Tatuzudo | 2018-12-06 13:30

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

p7f | 2018-12-06 16:30

:bust_in_silhouette: Reply From: SIsilicon

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.

All rigth, thanks for the answer!

Tatuzudo | 2018-12-06 01:17