From 0183340012a039c1fd4512ea274ed374626f0c48 Mon Sep 17 00:00:00 2001 From: Ninni Pipping Date: Mon, 3 Jul 2023 22:19:24 +0200 Subject: [PATCH] Improve error message for `Node.set_owner` --- doc/classes/Node.xml | 4 ++-- scene/main/node.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/classes/Node.xml b/doc/classes/Node.xml index 6bc167637e9..aaf889a09ad 100644 --- a/doc/classes/Node.xml +++ b/doc/classes/Node.xml @@ -858,8 +858,8 @@ [b]Note:[/b] Auto-generated names might include the [code]@[/code] character, which is reserved for unique names when using [method add_child]. When setting the name manually, any [code]@[/code] will be removed. - The node owner. A node can have any other node as owner (as long as it is a valid parent, grandparent, etc. ascending in the tree). When saving a node (using [PackedScene]), all the nodes it owns will be saved with it. This allows for the creation of complex [SceneTree]s, with instancing and subinstancing. - [b]Note:[/b] If you want a child to be persisted to a [PackedScene], you must set [member owner] in addition to calling [method add_child]. This is typically relevant for [url=$DOCS_URL/tutorials/plugins/running_code_in_the_editor.html]tool scripts[/url] and [url=$DOCS_URL/tutorials/plugins/editor/index.html]editor plugins[/url]. If [method add_child] is called without setting [member owner], the newly added [Node] will not be visible in the scene tree, though it will be visible in the 2D/3D view. + The node owner. A node can have any ancestor node as owner (i.e. a parent, grandparent, etc. node ascending in the tree). This implies that [method add_child] should be called before setting the owner, so that this relationship of parenting exists. When saving a node (using [PackedScene]), all the nodes it owns will be saved with it. This allows for the creation of complex scene trees, with instancing and subinstancing. + [b]Note:[/b] If you want a child to be persisted to a [PackedScene], you must set [member owner] in addition to calling [method add_child]. This is typically relevant for [url=$DOCS_URL/tutorials/plugins/running_code_in_the_editor.html]tool scripts[/url] and [url=$DOCS_URL/tutorials/plugins/editor/index.html]editor plugins[/url]. If a new node is added to the tree without setting its owner as an ancestor in that tree, it will be visible in the 2D/3D view, but not in the scene tree (and not persisted when packing or saving). Can be used to pause or unpause the node, or make the node paused based on the [SceneTree], or make it inherit the process mode from its parent (default). diff --git a/scene/main/node.cpp b/scene/main/node.cpp index 9ebd8f00a83..0d3a7eb0570 100644 --- a/scene/main/node.cpp +++ b/scene/main/node.cpp @@ -1906,7 +1906,7 @@ void Node::set_owner(Node *p_owner) { check = check->data.parent; } - ERR_FAIL_COND(!owner_valid); + ERR_FAIL_COND_MSG(!owner_valid, "Invalid owner. Owner must be an ancestor in the tree."); _set_owner_nocheck(p_owner);