Parents and owners

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By JulioYagami

What is the difference between parents and owners?

:bust_in_silhouette: Reply From: SIsilicon

This is what I can get from the docs.

  1. A node’s parent is a node that is one level up the node’s hierarchy.
  2. A node’s owner is one that the node will be saved along with. Eg: If you make a node from script in the editor, it will have a default owner of null. Therefore it won’t be saved with the currently edited scene.

I was just answering the same.

p7f | 2018-12-07 13:11

:bust_in_silhouette: Reply From: p7f

Hi,

Parent is the direct node above in hierarchy in your tree structure. For example, in the next tree:

->Node2D
—>Area2D
—>KinematicBody2D
------>AnimatedSprite

Node2D is parent of Area2D and KinematicBody2D, and KB2D is parent of AnimatedSprite.

Owner instead can be any node that is parent or grandparent etc. It is useful for packed scenes, for exampling in saving nodes at runtime. When you want to save a node, all the nodes it owns get saved also, but no the children it does not own. Also, from docs:

To keep track of the scene hierarchy (especially when instancing scenes into other scenes), an “owner” can be set for the node with set_owner. This keeps track of who instanced what. This is mostly useful when writing editors and tools, though.

Parent wont do in this case.