how can I use get_children() after I used queue_free() or free() on a node?

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

I have a main node A and a sub node of A called “B”, the problem is when I
queue_free() to node b and tries to see how many nodes in A it gives me the same number. I’m testing how many nodes inside A by using get_children() inside _physics_process(delta) function for testing purposes.

:bust_in_silhouette: Reply From: hilfazer

queue_free() does not delete a Node immediately so if you check children right after calling it you won’t see any change.

You may queue_free a Node and then remove it from tree

$"B".queue_free()
remove_child($"B")

At this point B will not be a child of A, although it won’t be destroyed yet.

free() function deletes a Node immediately but SceneTree is in some cases locked and no nodes can be removed from it. To make sure SceneTree isn’t locked use call_deferred

func foo():
	call_deferred("deleteB")

func deleteB():
	$"B".free()
	print(get_child_count())
	print(get_children())

Thank you , i understood many things from your comment.

Abdulrahman | 2018-12-21 13:02