diff --git a/Source/MetaCoreEditor/Private/MetaCoreEditorApp.cpp b/Source/MetaCoreEditor/Private/MetaCoreEditorApp.cpp index 291f5ce..8e2bbb0 100644 --- a/Source/MetaCoreEditor/Private/MetaCoreEditorApp.cpp +++ b/Source/MetaCoreEditor/Private/MetaCoreEditorApp.cpp @@ -931,7 +931,7 @@ void MetaCoreConfigureChineseFont() { void MetaCoreDrawSceneViewContextMenu(MetaCoreEditorContext& editorContext, MetaCoreId contextObjectId) { const MetaCoreGameObject contextObject = editorContext.GetScene().FindGameObject(contextObjectId); const bool hasContextObject = static_cast(contextObject); - const std::optional forcedParentId = hasContextObject ? std::optional(contextObjectId) : std::nullopt; + const std::optional forcedParentId = hasContextObject ? std::optional(contextObjectId) : std::optional(0); if (hasContextObject) { ImGui::TextDisabled("Object: %s", contextObject.GetName().c_str()); diff --git a/tests/MetaCoreSmokeTests.cpp b/tests/MetaCoreSmokeTests.cpp index 6e31a45..11bdfc3 100644 --- a/tests/MetaCoreSmokeTests.cpp +++ b/tests/MetaCoreSmokeTests.cpp @@ -356,6 +356,18 @@ void MetaCoreTestHierarchyEditingCommandsDirtyAndUndo() { MetaCoreExpect(scenePersistenceService->SaveCurrentScene(editorContext), "Hierarchy command scene should save after create"); MetaCoreExpect(!scenePersistenceService->IsSceneDirty(), "Hierarchy command scene should be clean after create save"); + editorContext.SelectOnly(*createdId); + const auto forcedRootId = sceneEditingService->CreateGameObject( + editorContext, + "ForcedRootObject", + false, + std::optional{0} + ); + MetaCoreExpect(forcedRootId.has_value(), "CreateGameObject with forced root parent should create an object"); + MetaCoreExpect(scene.FindGameObject(*forcedRootId).GetParentId() == 0, "CreateGameObject forced root parent should ignore active selection"); + MetaCoreExpect(scenePersistenceService->SaveCurrentScene(editorContext), "Hierarchy command scene should save after forced root create"); + MetaCoreExpect(!scenePersistenceService->IsSceneDirty(), "Hierarchy command scene should be clean after forced root create save"); + MetaCoreExpect(sceneEditingService->RenameGameObject(editorContext, *createdId, "HierarchyObjectRenamed"), "RenameGameObject command should rename object"); MetaCoreExpect(scenePersistenceService->IsSceneDirty(), "RenameGameObject command should mark scene dirty"); MetaCoreExpect(editorContext.UndoCommand(), "Undo RenameGameObject should succeed");