Fix undo for create editor entity (#6785)

* Avoid undoing twice when undo is hit for CreateNewEditorEntity

Signed-off-by: srikappa-amzn <82230713+srikappa-amzn@users.noreply.github.com>

* Moved an assert immediately after entity creation

Signed-off-by: srikappa-amzn <82230713+srikappa-amzn@users.noreply.github.com>
This commit is contained in:
srikappa-amzn
2022-01-10 17:01:50 -08:00
committed by GitHub
parent 6ea5c4dc44
commit d3a99235aa
@@ -226,7 +226,15 @@ namespace AzToolsFramework
AZ::EntityId EditorEntityContextComponent::CreateNewEditorEntity(const char* name)
{
AZ::Entity* entity = CreateEntity(name);
FinalizeEditorEntity(entity);
AZ_Assert(entity != nullptr, "Entity with name %s couldn't be created.", name);
if (m_isLegacySliceService)
{
FinalizeEditorEntity(entity);
}
else
{
EditorEntityContextNotificationBus::Broadcast(&EditorEntityContextNotification::OnEditorEntityCreated, entity->GetId());
}
return entity->GetId();
}
@@ -253,8 +261,16 @@ namespace AzToolsFramework
return AZ::EntityId();
}
entity = aznew AZ::Entity(entityId, name);
AZ_Assert(entity != nullptr, "Entity with name %s couldn't be created.", name);
AddEntity(entity);
FinalizeEditorEntity(entity);
if (m_isLegacySliceService)
{
FinalizeEditorEntity(entity);
}
else
{
EditorEntityContextNotificationBus::Broadcast(&EditorEntityContextNotification::OnEditorEntityCreated, entity->GetId());
}
return entity->GetId();
}