summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2022-10-31 10:33:51 +0100
committerRémi Verschelde <rverschelde@gmail.com>2022-10-31 10:33:51 +0100
commit32548f96083f9725183773e4c4a634cb0441e0f1 (patch)
tree422dad9d51a1dc55af90144a027adb84837bd724
parent68623c75b31727783ae11514d9ded353436b4b91 (diff)
parent64c20a51c12ee69c266eaae0fee5d47cc2490971 (diff)
Merge pull request #67467 from timothyqiu/who-ami-i
Fix get_path() error when calling get_node()
-rw-r--r--scene/main/node.cpp15
1 files changed, 13 insertions, 2 deletions
diff --git a/scene/main/node.cpp b/scene/main/node.cpp
index 2ea45df309..25b38eb15b 100644
--- a/scene/main/node.cpp
+++ b/scene/main/node.cpp
@@ -1341,12 +1341,23 @@ Node *Node::get_node(const NodePath &p_path) const {
Node *node = get_node_or_null(p_path);
if (unlikely(!node)) {
+ // Try to get a clear description of this node in the error message.
+ String desc;
+ if (is_inside_tree()) {
+ desc = get_path();
+ } else {
+ desc = get_name();
+ if (desc.is_empty()) {
+ desc = get_class();
+ }
+ }
+
if (p_path.is_absolute()) {
ERR_FAIL_V_MSG(nullptr,
- vformat(R"(Node not found: "%s" (absolute path attempted from "%s").)", p_path, get_path()));
+ vformat(R"(Node not found: "%s" (absolute path attempted from "%s").)", p_path, desc));
} else {
ERR_FAIL_V_MSG(nullptr,
- vformat(R"(Node not found: "%s" (relative to "%s").)", p_path, get_path()));
+ vformat(R"(Node not found: "%s" (relative to "%s").)", p_path, desc));
}
}