0 votes

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?

in Engine by (33 points)

1 Answer

+1 vote

Yes, see tree_exiting and tree_exited here - https://docs.godotengine.org/en/stable/classes/class_node.html#signals

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():
    emit_signal("terminate_initiated")
    queue_free()

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.

by (449 points)

Ah very interesting,

Thank you.

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 Frequently asked questions and 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 [email protected] with your username.