Godot version:
3.0.6 and 3.1 alpha1
OS/device including version:
Arch Linux
Issue description:
Let's assume that there is a very simple instanced scene:
Owner
│
└── Node
Node node has script attached, that connects to the Owner tree_exiting signal. When this signal is emitted, I would like to access the Owner node by using owner variable (or get_owner method). Unfortunately, when this signal is emitted, this variable is already set to null, even though Owner node is still the owner of the Node (I can access Owner node by using get_parent).
Of course I could pass the owner in binds array in connect method, use get_parent method, store reference to the owner in a different variable, or create my own signal and method for deletion of the Owner. I'm just not sure if this is expected behavior, because tree_exiting signal is emitted before the node and its children are removed, so owner should still be accessible.
Steps to reproduce:
tree_exiting signalowner variable in a method that is called on the emission of the signal in point 3Minimal reproduction project:
Project created in version 3.1 alpha1
When playing the project, press Delete key on keyboard to delete the Owner.
Look at the Output in the Editor window. Notice the Owner: [Object:null] (owner variable) and Parent: [Spatial:XXXX] (get_parent method).
All the code is in the Child.gd file.
The issue is at https://github.com/godotengine/godot/blob/b17e71b6e5e035f49b5b3b5b55b9cdac80215d72/scene/main/node.cpp#L145
where the owner is set to NULL before tree_exiting is ever emitted, not sure what the right fix here is.
That's an expected behavior. The owner is one of the node's parents that corresponds to the scene root the node is in.
When the node exits the tree it has no parents anymore, so it's expected that get_owner and get_parent return null.
If you really need them, just store the nodes in the _ready function or somehow like that.
I'd expect that behaviour of tree_exited, where the node has left the scene tree, but exiting is before/during, so should ownership still be a valid thing, as "the node is still active but about to exit the tree" with tree_exiting?
The signal might be renamed indeed.
Arf, I have just figured out that we also have also a tree_exited signal. In that case I agree having the possibility to access the parent/owner would make sense.
Most helpful comment
I'd expect that behaviour of
tree_exited, where the node has left the scene tree, but exiting is before/during, so should ownership still be a valid thing, as "the node is still active but about to exit the tree" withtree_exiting?