+1 vote

What is the difference between parents and owners?

asked Dec 7, 2018 in Engine by JulioYagami (637 points)

2 Answers

+3 votes
Best answer

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.
answered Dec 7, 2018 by SIsilicon (3,796 points)
selected Dec 7, 2018 by JulioYagami

I was just answering the same.

+1 vote

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.

answered Dec 7, 2018 by p7f (3,208 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.