_init()
is the constructor and in that sense is supposed to be used for internal state initialization. It's possible to set up the scene from here as well, but there are cleaner alternatives.
The direct and indirect children of the scene's root node receive the PARENTED
notification one by one as they are added to the isolated node tree. You can hook into this notification by checking for NOTIFICATION_PARENTED
in the _notification()
callback:
func _notification(what):
match what:
NOTIFICATION_PARENTED:
print("node added as child to its direct parent")
Nodes are added from top to bottom, depth-first.
Finally, by the same mechanism, the root node of the scene receives NOTIFICATION_INSTANCED
once all children have been added to their parents. Since the root node does not have a parent during scene instantiation, it will not receive the NOTIFICATION_PARENTED
notification.