LYN-4133 | Prefab Container Transform stores non-default values to template on Create Prefab (#1038)

* Show container transforms, reset container transform to zero before saving a prefab after create.

* Fix order of operations to prevent patching issues

* Reset the entity to the Identity Transform instead of the default constructor to correctly set the scale to 1.0
This commit is contained in:
Danilo Aimini
2021-06-02 14:45:43 -07:00
committed by GitHub
parent d697fbe366
commit 8a7f156e2c
2 changed files with 26 additions and 3 deletions
@@ -243,11 +243,33 @@ namespace AzToolsFramework
instanceToCreate->get(), commonRootEntityOwningInstance->get().GetTemplateId(), undoBatch.GetUndoBatch(),
AZStd::move(patch));
// Reset the transform of the container entity so that the new values aren't saved in the new prefab's dom.
// The new values were saved in the link, so propagation will apply them correctly.
{
AZ::Entity* containerEntity = GetEntityById(containerEntityId);
PrefabDom containerBeforeReset;
m_instanceToTemplateInterface->GenerateDomForEntity(containerBeforeReset, *containerEntity);
AZ::TransformBus::Event(containerEntityId, &AZ::TransformBus::Events::SetParent, AZ::EntityId());
AZ::TransformBus::Event(containerEntityId, &AZ::TransformBus::Events::SetLocalTM, AZ::Transform::CreateIdentity());
PrefabDom containerAfterReset;
m_instanceToTemplateInterface->GenerateDomForEntity(containerAfterReset, *containerEntity);
// Update the state of the entity
PrefabUndoEntityUpdate* state = aznew PrefabUndoEntityUpdate(AZStd::to_string(static_cast<AZ::u64>(containerEntityId)));
state->SetParent(undoBatch.GetUndoBatch());
state->Capture(containerBeforeReset, containerAfterReset, containerEntityId);
state->Redo();
}
// This clears any entities marked as dirty due to reparenting of entities during the process of creating a prefab.
// We are doing this so that the changes in those enities are not queued up twice for propagation.
// We are doing this so that the changes in those entities are not queued up twice for propagation.
AzToolsFramework::ToolsApplicationRequestBus::Broadcast(
&AzToolsFramework::ToolsApplicationRequestBus::Events::ClearDirtyEntities);
// Select Container Entity
{
auto selectionUndo = aznew SelectionCommand({containerEntityId}, "Select Prefab Container Entity");
@@ -969,7 +969,8 @@ namespace AzToolsFramework
{
// Build up components to display
SharedComponentArray sharedComponentArray;
BuildSharedComponentArray(sharedComponentArray, selectionEntityTypeInfo != SelectionEntityTypeInfo::OnlyStandardEntities);
BuildSharedComponentArray(sharedComponentArray,
!(selectionEntityTypeInfo == SelectionEntityTypeInfo::OnlyStandardEntities || selectionEntityTypeInfo == SelectionEntityTypeInfo::OnlyPrefabEntities));
if (sharedComponentArray.size() == 0)
{