Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Node: Rename child_exited_tree to child_exiting_tree #62241

Merged
merged 1 commit into from
Jun 20, 2022

Conversation

akien-mga
Copy link
Member

The name was confusing as this signal is emitted around the same time as
tree_exiting and NOTIFICATION_EXIT_TREE, i.e. while the child node is
still in tree.

Fixes #59210.

@akien-mga akien-mga added enhancement topic:core cherrypick:3.x Considered for cherry-picking into a future 3.x release labels Jun 20, 2022
@akien-mga akien-mga added this to the 4.0 milestone Jun 20, 2022
@akien-mga akien-mga requested review from a team as code owners June 20, 2022 07:56
@akien-mga
Copy link
Member Author

For the record, I don't really see a clear need for an actual child_exited_tree that would be emitted once the child node has fully exited the tree, because at this stage it's a bit late to do any related changes (and to even know what node this was, as it might have been freed from memory if it exited the tree due to a call to free() or queue_free()).

Still, here's a quick workaround if someone really needs this, you can connect to child_exiting_tree and there connect to the child node's tree_exited, e.g. with a lambda. Example code adapted from the MRP in #59210:

extends Node2D

var someNode

func _ready():
	someNode = get_node("Node2D")
	child_exited_tree.connect(onChildExited)
	remove_child(someNode)
	
func onChildExited(node):
	node.tree_exited.connect(
		func():
			# Do stuff. This is a lambda in parent scope.
			print(get_name()) # Root
			print(get_child_count()) # 0
	)

The name was confusing as this signal is emitted around the same time as
`tree_exiting` and `NOTIFICATION_EXIT_TREE`, i.e. while the child node is
still in tree.

Fixes godotengine#59210.
@akien-mga
Copy link
Member Author

Added some more documentation to clarify the order in which the various tree related signals and notifications are received.

@akien-mga akien-mga merged commit 8e3d9a2 into godotengine:master Jun 20, 2022
@akien-mga akien-mga deleted the node-child-exiting-tree branch June 20, 2022 10:28
@akien-mga
Copy link
Member Author

Cherry-picked for 3.5.

@akien-mga akien-mga removed the cherrypick:3.x Considered for cherry-picking into a future 3.x release label Jun 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

child_exited_tree signal fires before child has exited the tree
2 participants