diff --git a/src/user/user_objects.cc b/src/user/user_objects.cc index 7945ec11..83565a66 100644 --- a/src/user/user_objects.cc +++ b/src/user/user_objects.cc @@ -917,8 +917,10 @@ mjCBody& mjCBody::operator+=(const mjCFrame& other) { CopyList(lights, subtree->lights, fmap, &other); if (!model->deepcopy_) { + std::string name = subtree->name; subtree->SetModel(model); subtree->NameSpace(other_model); + subtree->name = name; } int nbodies = (int)subtree->bodies.size(); diff --git a/test/user/user_api_test.cc b/test/user/user_api_test.cc index 899232d3..6d22cdf5 100644 --- a/test/user/user_api_test.cc +++ b/test/user/user_api_test.cc @@ -1193,6 +1193,9 @@ TEST_F(MujocoTest, AttachFrame) { // check that the spec was copied EXPECT_THAT(mjs_findSpec(parent, "child"), NotNull()); + // check that the parent body was not namespaced + EXPECT_THAT(mjs_findBody(child, "world"), NotNull()); + // compile new model mjModel* m_attached = mj_compile(parent, 0); EXPECT_THAT(m_attached, NotNull());