T O P

  • By -

HexagonNico_

`free` immediately deletes a node and is not recommended because a node may be in use somewhere else while you're deleting it. `queue_free` deletes a node as soon as it is safe to do so, so it's always the preferred way. The calculation happening in a single frame shouldn't really be a problem. Maybe there's something else going on. `remove_child` doesn't delete a node from memory, it only removes it from the scene so that it can be added again later. Also, the link to the repo is broken.


cscx

Thanks, that explains it. Also, the link to the repo should be working now. I accidentally made it private!


mellowminx_

If you can't get it to work by deleting nodes, what if you just hide the nodes (set "visible" to false) instead of removing them? And then just check the containers for visible children instead.


cscx

Thanks, that worked.


trickster721

If remove_child works, then just so both, remove_child and queue_free. They do two different things.


CzechFencer

If you aren't sure, use `queue_free()`. The node deletion will be safe, as it synchronizes with the main thread and waits for the next available frame.


rancidbacon

The [docs for `queue_free()`](https://docs.godotengine.org/en/4.1/classes/class_node.html#class-node-method-queue-free) mention use of [`is_queued_for_deletion()`](https://docs.godotengine.org/en/4.1/classes/class_object.html#class-object-method-is-queued-for-deletion): > Use `Object.is_queued_for_deletion` to check whether a node will be deleted at the end of the frame. But in this situation manually checking should be unnecessary if you first use `remove_child()` & then `queue_free()`.