Skip to content

Commit 65e90ca

Browse files
authored
Merge pull request o3de#17641 from aws-lumberyard-dev/daimini/Prefabs/FixDuplicateSelection
Fix manipulators showing up incorrectly after duplicate
2 parents 1076f41 + e5de28e commit 65e90ca

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabPublicHandler.cpp

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <AzToolsFramework/Entity/EditorEntityContextBus.h>
1919
#include <AzToolsFramework/Entity/EditorEntityHelpers.h>
2020
#include <AzToolsFramework/Entity/EditorEntityInfoBus.h>
21+
#include <AzToolsFramework/Entity/EditorEntitySortComponent.h>
2122
#include <AzToolsFramework/Entity/PrefabEditorEntityOwnershipInterface.h>
2223
#include <AzToolsFramework/Entity/ReadOnly/ReadOnlyEntityInterface.h>
2324
#include <AzToolsFramework/Prefab/EditorPrefabComponent.h>
@@ -36,14 +37,23 @@
3637
#include <AzToolsFramework/Prefab/Undo/PrefabUndoUpdateLink.h>
3738
#include <AzToolsFramework/Prefab/PrefabUndoHelpers.h>
3839
#include <AzToolsFramework/ToolsComponents/TransformComponent.h>
39-
#include <AzToolsFramework/Entity/EditorEntitySortComponent.h>
40+
#include <AzToolsFramework/ViewportSelection/EditorTransformComponentSelectionRequestBus.h>
4041

4142
#include <QString>
43+
#include <QTimer>
4244

4345
namespace AzToolsFramework
4446
{
4547
namespace Prefab
4648
{
49+
PrefabPublicHandler::PrefabPublicHandler()
50+
{
51+
// Detect whether this is being run in the Editor or during a Unit Test.
52+
AZ::ApplicationTypeQuery appType;
53+
AZ::ComponentApplicationBus::Broadcast(&AZ::ComponentApplicationBus::Events::QueryApplicationType, appType);
54+
m_isRunningInEditor = (!appType.IsValid() || appType.IsEditor());
55+
}
56+
4757
void PrefabPublicHandler::RegisterPrefabPublicHandlerInterface()
4858
{
4959
m_prefabFocusHandler.RegisterPrefabFocusInterface();
@@ -1340,8 +1350,25 @@ namespace AzToolsFramework
13401350
// Select the duplicated entities/instances
13411351
auto selectionUndo = aznew SelectionCommand(duplicatedEntityAndInstanceIds, "Select Duplicated Entities/Instances");
13421352
selectionUndo->SetParent(undoBatch.GetUndoBatch());
1343-
ToolsApplicationRequestBus::Broadcast(
1344-
&ToolsApplicationRequestBus::Events::SetSelectedEntities, duplicatedEntityAndInstanceIds);
1353+
1354+
// Only delay selection in the Editor to ensure the manipulators in the viewport are refreshed correctly.
1355+
if (m_isRunningInEditor)
1356+
{
1357+
QTimer::singleShot(
1358+
0,
1359+
[duplicatedEntityAndInstanceIds]()
1360+
{
1361+
ToolsApplicationRequestBus::Broadcast(
1362+
&ToolsApplicationRequestBus::Events::SetSelectedEntities, duplicatedEntityAndInstanceIds);
1363+
}
1364+
);
1365+
}
1366+
else
1367+
{
1368+
ToolsApplicationRequestBus::Broadcast(
1369+
&ToolsApplicationRequestBus::Events::SetSelectedEntities, duplicatedEntityAndInstanceIds);
1370+
}
1371+
13451372
}
13461373

13471374
return AZ::Success(AZStd::move(duplicatedEntityAndInstanceIds));

Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabPublicHandler.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ namespace AzToolsFramework
3939
AZ_CLASS_ALLOCATOR(PrefabPublicHandler, AZ::SystemAllocator);
4040
AZ_RTTI(PrefabPublicHandler, "{35802943-6B60-430F-9DED-075E3A576A25}", PrefabPublicInterface);
4141

42+
PrefabPublicHandler();
43+
4244
void RegisterPrefabPublicHandlerInterface();
4345
void UnregisterPrefabPublicHandlerInterface();
4446

@@ -212,6 +214,8 @@ namespace AzToolsFramework
212214
PrefabFocusHandler m_prefabFocusHandler;
213215

214216
uint64_t m_newEntityCounter = 1;
217+
218+
bool m_isRunningInEditor = true;
215219
};
216220
} // namespace Prefab
217221
} // namespace AzToolsFramework

0 commit comments

Comments
 (0)