cybereality Hello, and thank you for the response.
Unfortunately, like you said, both child_exiting_tree()
and tree_exiting()
(in the child nodes) are called when the scene is closed, similarly to NOTIFICATION_UNPARENTED
.
Those additional checks you mention are the real problem, as the editor just doesn't seem to distinguish between a scene change and direct object removal by the user.
Additionally, it seems I was completely wrong about the removal order of children, and they are actually removed in reversed index order: bottom to top.
However, through testing, I found out a few things about removal order:
All NOTIFICATION_EXIT_TREE
events, for all objects, are sent out before any NOTIFICATION_UNPARENTED
events.
While child objects all receive the NOTIFICATION_EXIT_TREE
event before the parent does, the opposite is true for NOTIFICATION_UNPARENTED
: the parent receives it first.
So, when the child receives its NOTIFICATION_UNPARENTED
event, I can check if the parent is still inside the scene tree with get_parent().is_inside_tree()
. If it is, then the scene is not being closed.
This is encouraging, and probably good enough. But the Node page doesn't confirm this behaviour, so it does bring me back to my initial question: is this reliable?