Can a node detect queue_free() ?

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

Can a node detect when a node is deleted via queue_free() in a similar way to how an area2D can detect bodies exiting it, and can this be used in code?

:bust_in_silhouette: Reply From: denxi

Yes, see tree_exiting and tree_exited here - Node — Godot Engine (stable) documentation in English

However, depending on your code structure, it may be best to just have the node that’s being removed use a custom function like the following:

func terminate():

Although this code will emit the signal before the node is actually freed, so if you require a signal to specifically be emitted afterwards, then tree_exited is probably your best bet.

Ah very interesting,

Thank you.

MIna | 2020-11-14 12:16