queue_free and get_children

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By agent3bood
:warning: Old Version Published before Godot 3 was released.

update
That was my fault, I was not clearing the correct node.
free() and queue_free() works fine and as described.

I am removing a node using

self.queue_free()

the node is being removed from the screen, all is ok, but when I am checking from the parent

self.get_children()

the node is returned!
also

self.get_child_count()

does not reset to zero!

Is this way correct to remove the node?

do you check in the same frame where you queue_free?

rustyStriker | 2017-12-18 22:24

I keep checking in the _process(), but it is not geting reseted.

agent3bood | 2017-12-19 16:32

:bust_in_silhouette: Reply From: Zylann

queue_free doesn’t immediately remove the node from the tree, it does that at the end of the frame, due to many unexpected side-effects using free could cause (unless you really know what you are doing).

You can try to remove the node from the tree though, if you just want it to not be there.

The issue continue as long as the game is running, I waited minutes fot it!
I am removing a level and adding a new one, is there a better wat?
Every level is a scene thet I inctance and add to the root node by code.

agent3bood | 2017-12-19 04:45

If the node is still there minutes after you did queue_free (or removed from tree), it’s very likely you made a mistake. Do you see any error in the console? What is your code?

Zylann | 2017-12-19 16:28

No errors, I have tried free() alao with the same results. The scene is getting removed from the game visualy but in the code it is not.

agent3bood | 2017-12-19 16:34

Can I see your code?

Zylann | 2017-12-19 16:49

I will post it later today,

agent3bood | 2017-12-19 16:52

# this is the child node
func _process(delta):
	if(get_overlapping_areas().size() > 0):
		var overlap = get_overlapping_areas()[0]
		if(overlap.is_in_group("drag") and overlap.get_parent() == self.get_parent()):
			overlap.set_pos(self.get_pos())
			self.get_parent().emit_signal("dropped")



# this is the parent node
signal dropped
func _ready():
	self.connect("dropped", self, "on_dropped")
	
func on_dropped():
	self.queue_free()

agent3bood | 2017-12-19 20:12

And the parent is still in the tree? Are you sure it was really called? How did you deduce it’s still in the tree? Do you still see it in the remote debugger?

Does this happen too in a minimal project? I made one with the same structure as your code and it works.

(Note: not sure why you used a signal here though, why not just call get_parent().on_dropped() ?)

Zylann | 2017-12-19 20:51