From 2f5af689fd93d3f63cbdb0b4a2b69999c4286a1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A3=8E=E9=9D=92=E5=B1=B1?= Date: Thu, 17 Jul 2025 21:57:22 +0800 Subject: [PATCH] Fix the absolute `NodePath` was calculated incorrectly when "Reparent to New Node" Since the new parent node has not yet been added to the tree, the `new_base_path` needs to be calculated using the `base_path`. --- editor/docks/scene_tree_dock.cpp | 7 ++++++- scene/3d/mesh_instance_3d.cpp | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/editor/docks/scene_tree_dock.cpp b/editor/docks/scene_tree_dock.cpp index 4133fd7975e..1fab780f98a 100644 --- a/editor/docks/scene_tree_dock.cpp +++ b/editor/docks/scene_tree_dock.cpp @@ -1966,7 +1966,6 @@ void SceneTreeDock::fill_path_renames(Node *p_node, Node *p_new_parent, HashMap< base_path.push_back(n->get_name()); n = n->get_parent(); } - base_path.reverse(); Vector new_base_path; if (p_new_parent) { @@ -1976,8 +1975,14 @@ void SceneTreeDock::fill_path_renames(Node *p_node, Node *p_new_parent, HashMap< n = n->get_parent(); } + // For the case Reparent to New Node, the new parent has not yet been added to the tree. + if (!p_new_parent->is_inside_tree()) { + new_base_path.append_array(base_path); + } + new_base_path.reverse(); } + base_path.reverse(); _fill_path_renames(base_path, new_base_path, p_node, p_renames); } diff --git a/scene/3d/mesh_instance_3d.cpp b/scene/3d/mesh_instance_3d.cpp index 09670358161..660d4f7ccb2 100644 --- a/scene/3d/mesh_instance_3d.cpp +++ b/scene/3d/mesh_instance_3d.cpp @@ -176,7 +176,7 @@ void MeshInstance3D::_resolve_skeleton_path() { Ref new_skin_reference; if (!skeleton_path.is_empty()) { - Skeleton3D *skeleton = Object::cast_to(get_node(skeleton_path)); + Skeleton3D *skeleton = Object::cast_to(get_node_or_null(skeleton_path)); // skeleton_path may be outdated when reparenting. if (skeleton) { if (skin_internal.is_null()) { new_skin_reference = skeleton->register_skin(skeleton->create_skin_from_rest_transforms());