diff --git a/scene/main/node.cpp b/scene/main/node.cpp index cc0f07a6e4..9b27d7c007 100644 --- a/scene/main/node.cpp +++ b/scene/main/node.cpp @@ -2416,14 +2416,14 @@ NodePath Node::get_path() const { const Node *n = this; Vector path; + path.resize(data.depth); + StringName *ptrw = path.ptrw(); while (n) { - path.push_back(n->get_name()); + ptrw[n->data.depth - 1] = n->get_name(); n = n->data.parent; } - path.reverse(); - data.path_cache = memnew(NodePath(path, true)); return *data.path_cache;