Explorar o código

Clarify purpose of `Node.owner` in Running code in the editor

(cherry picked from commit f6b4edcdae0c1f4aa951053adef1fc393574886e)
Hugo Locurcio %!s(int64=3) %!d(string=hai) anos
pai
achega
f56ea1952a
Modificáronse 1 ficheiros con 19 adicións e 1 borrados
  1. 19 1
      tutorials/plugins/running_code_in_the_editor.rst

+ 19 - 1
tutorials/plugins/running_code_in_the_editor.rst

@@ -215,7 +215,13 @@ Modify  ``_process()`` to include the rotation speed.
 Instancing scenes
 -----------------
 
-You can instantiate packed scenes normally and add them to the scene currently opened in the editor. Be sure to set the scene root as the owner of all the nodes created this way or the nodes won't be visible in the editor.
+You can instantiate packed scenes normally and add them to the scene currently
+opened in the editor. By default, nodes or scenes added with
+:ref:`Node.add_child(node) <class_Node_method_add_child>` are **not** visible
+in the Scene tree dock and are **not** persisted to disk. If you wish the node
+or scene to be visible in the scene tree dock and persisted to disk when saving
+the scene, you need to set the child node's :ref:`owner <class_Node_property_owner>`
+property to the currently edited scene root.
 
 If you are using ``tool``:
 
@@ -225,6 +231,9 @@ If you are using ``tool``:
     func _ready():
         var node = Spatial.new()
         add_child(node) # Parent could be any node in the scene
+
+        # The line below is required to make the node visible in the Scene tree dock
+        # and persist changes made by the tool script to the saved scene file.
         node.set_owner(get_tree().edited_scene_root)
 
  .. code-tab:: csharp
@@ -233,6 +242,9 @@ If you are using ``tool``:
     {
         var node = new Spatial();
         AddChild(node); // Parent could be any node in the scene
+
+        // The line below is required to make the node visible in the Scene tree dock
+        // and persist changes made by the tool script to the saved scene file.
         node.Owner = GetTree().EditedSceneRoot;
     }
 
@@ -245,6 +257,9 @@ If you are using :ref:`EditorScript<class_EditorScript>`:
         var parent = get_scene().find_node("Parent") # Parent could be any node in the scene
         var node = Spatial.new()
         parent.add_child(node)
+
+        # The line below is required to make the node visible in the Scene tree dock
+        # and persist changes made by the tool script to the saved scene file.
         node.set_owner(get_scene())
 
  .. code-tab:: csharp
@@ -254,6 +269,9 @@ If you are using :ref:`EditorScript<class_EditorScript>`:
         var parent = GetScene().FindNode("Parent"); // Parent could be any node in the scene
         var node = new Spatial();
         parent.AddChild(node);
+
+        // The line below is required to make the node visible in the Scene tree dock
+        // and persist changes made by the tool script to the saved scene file.
         node.Owner = GetScene();
     }