Node has notifications NOTIFICATION_PARENTED
and NOTIFICATION_UNPARENTED
. This is an usage example:
func _notification(what):
if what == NOTIFICATION_PARENTED:
prints("Now I am a child of", get_parent().get_name())
elif what == NOTIFICATION_UNPARENTED:
print("I have been orphaned")
About the parent, I did not find a signal nor a notification for child added, but you could achieve that by overriding add_child
:
func add_child(node):
.add_child(node)
prints("I just fathered", node.get_name())
And you could do the same with remove_child
.
I forgot to mention the overridden add_child
method won't be called for children on a packed scene, so you may want to iterate through all the children on _ready
and call your method there too.