summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <remi@verschelde.fr>2021-07-15 15:11:21 +0200
committerGitHub <noreply@github.com>2021-07-15 15:11:21 +0200
commitf79e79d479e687cbc8448bf38dec62491e85c88b (patch)
tree359278435fede603b2a930a67dff1df742f970e4
parent912792cfe6e5432067525554b05f6d965487fd18 (diff)
parent3ca25ffe8a8b2726cd959b20efe1a4066c75a6b6 (diff)
Merge pull request #38819 from EricEzaM/improve-to_string-for-nodes
Added Node name to print() of all Nodes by making to_string() in Object virtual, so it can be overriden in C++.
-rw-r--r--scene/main/node.cpp12
-rw-r--r--scene/main/node.h2
2 files changed, 14 insertions, 0 deletions
diff --git a/scene/main/node.cpp b/scene/main/node.cpp
index 787b283e8c..0935e64678 100644
--- a/scene/main/node.cpp
+++ b/scene/main/node.cpp
@@ -1822,6 +1822,18 @@ Node *Node::get_deepest_editable_node(Node *p_start_node) const {
return node;
}
+String Node::to_string() {
+ if (get_script_instance()) {
+ bool valid;
+ String ret = get_script_instance()->to_string(&valid);
+ if (valid) {
+ return ret;
+ }
+ }
+
+ return (get_name() ? String(get_name()) + ":" : "") + Object::to_string();
+}
+
void Node::set_scene_instance_state(const Ref<SceneState> &p_state) {
data.instance_state = p_state;
}
diff --git a/scene/main/node.h b/scene/main/node.h
index c6727ce884..20315d7a86 100644
--- a/scene/main/node.h
+++ b/scene/main/node.h
@@ -329,6 +329,8 @@ public:
bool is_editable_instance(const Node *p_node) const;
Node *get_deepest_editable_node(Node *p_start_node) const;
+ virtual String to_string() override;
+
/* NOTIFICATIONS */
void propagate_notification(int p_notification);