From e7857120b0896774f082898842e7e5e984f184c6 Mon Sep 17 00:00:00 2001 From: Danilo Aimini <82231674+AMZN-daimini@users.noreply.github.com> Date: Mon, 7 Feb 2022 13:35:48 -0800 Subject: [PATCH] Fix issue with clearing the parent entityId in the transform would result in prefab reparenting. (#7464) Signed-off-by: Danilo Aimini <82231674+AMZN-daimini@users.noreply.github.com> --- .../ToolsComponents/TransformComponent.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/ToolsComponents/TransformComponent.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/ToolsComponents/TransformComponent.cpp index 55961aa703..014bade347 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/ToolsComponents/TransformComponent.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/ToolsComponents/TransformComponent.cpp @@ -29,7 +29,7 @@ #include #include #include -#include +#include #include #include #include @@ -963,18 +963,22 @@ namespace AzToolsFramework if (!m_parentEntityId.IsValid()) { - // If Prefabs are enabled, reroute the invalid id to the level root + // If Prefabs are enabled, reroute the invalid id to the focused prefab container entity id bool isPrefabSystemEnabled = false; AzFramework::ApplicationRequests::Bus::BroadcastResult( isPrefabSystemEnabled, &AzFramework::ApplicationRequests::IsPrefabSystemEnabled); if (isPrefabSystemEnabled) { - auto prefabPublicInterface = AZ::Interface::Get(); + auto prefabFocusPublicInterface = AZ::Interface::Get(); - if (prefabPublicInterface) + if (prefabFocusPublicInterface) { - m_parentEntityId = prefabPublicInterface->GetLevelInstanceContainerEntityId(); + auto editorEntityContextId = AzFramework::EntityContextId::CreateNull(); + EditorEntityContextRequestBus::BroadcastResult( + editorEntityContextId, &EditorEntityContextRequests::GetEditorEntityContextId); + + m_parentEntityId = prefabFocusPublicInterface->GetFocusedPrefabContainerEntityId(editorEntityContextId); refreshLevel = AZ::Edit::PropertyRefreshLevels::ValuesOnly; } }