diff --git a/scene/main/node.cpp b/scene/main/node.cpp index 9fe529155e5..79982552cf5 100644 --- a/scene/main/node.cpp +++ b/scene/main/node.cpp @@ -2396,14 +2396,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;