+1 vote

hello,
I'm not yet very good at understanding queue_free().
I know that calling node.queue_free() put that node in queue for being deleted, but what happen to its children? I thought they also would be freed before that parent node, but my experience taught me it doesn't happen, or it doesn't happen this way.

My project started to crash after doing something I'm not here for. I found the solution when I deleted a specific kind of node

code speaking, this script made application to crash:

onready var node_ref = weakref($ParentToDelete)
get_node("ParentToDelete").queue_free()
if node_ref.get_ref() == null:
    get_tree().change_scene(some_new_scene)

changing as following, application crashes no more:

#-- changed 
    onready var node_ref = weakref(get_node("ParentToDelete\child"))   
# -- the same than before
    get_node("ParentToDelete").queue_free()
    if node_ref.get_ref() == null:
        get_tree().change_scene(some_new_scene)

So, my question is: how 'queue_free()` works on children when called on parent node?

thanks
Graziano

in Engine by (52 points)
edited by

1 Answer

0 votes

All of child nodes under the parent node will be freed too.
otherwise, it is horrible whenever using queue_free() function.

by (9,736 points)

actually deleting children doesn't work properly.

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 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 webmaster@godotengine.org with your username.