LYN-4866 Fixed net entities indices when creating net spawnable
Signed-off-by: pereslav <pereslav@amazon.com>
This commit is contained in:
+16
-10
@@ -46,10 +46,11 @@ namespace AzToolsFramework::Prefab::SpawnableUtils
|
||||
}
|
||||
}
|
||||
|
||||
template<typename EntityPtr>
|
||||
void OrganizeEntitiesForSorting(
|
||||
AzFramework::Spawnable::EntityList& entities,
|
||||
AZStd::vector<EntityPtr>& entities,
|
||||
AZStd::unordered_set<AZ::EntityId>& existingEntityIds,
|
||||
AZStd::unordered_map<AZ::EntityId, AzFramework::Spawnable::EntityList>& parentIdToChildren,
|
||||
AZStd::unordered_map<AZ::EntityId, AZStd::vector<EntityPtr>>& parentIdToChildren,
|
||||
AZStd::vector<AZ::EntityId>& candidateIds,
|
||||
size_t& removedEntitiesCount)
|
||||
{
|
||||
@@ -90,7 +91,7 @@ namespace AzToolsFramework::Prefab::SpawnableUtils
|
||||
// entities with no transform component will be treated like entities with no parent.
|
||||
AZ::EntityId parentId;
|
||||
if (AZ::TransformInterface* transformInterface =
|
||||
AZ::EntityUtils::FindFirstDerivedComponent<AZ::TransformInterface>(entity.get()))
|
||||
AZ::EntityUtils::FindFirstDerivedComponent<AZ::TransformInterface>(&(*entity)))
|
||||
{
|
||||
parentId = transformInterface->GetParentId();
|
||||
if (parentId == entityId)
|
||||
@@ -104,8 +105,7 @@ namespace AzToolsFramework::Prefab::SpawnableUtils
|
||||
}
|
||||
|
||||
auto& children = parentIdToChildren[parentId];
|
||||
children.emplace_back(nullptr);
|
||||
children.back().swap(entity);
|
||||
children.emplace_back(AZStd::move(entity));
|
||||
}
|
||||
|
||||
// clear 'entities', we'll refill it in sorted order.
|
||||
@@ -125,9 +125,10 @@ namespace AzToolsFramework::Prefab::SpawnableUtils
|
||||
|
||||
}
|
||||
|
||||
template<typename EntityPtr>
|
||||
void TraceParentingLoop(
|
||||
const AZ::EntityId& parentFromLoopId,
|
||||
const AZStd::unordered_map<AZ::EntityId, AzFramework::Spawnable::EntityList>& parentIdToChildren)
|
||||
const AZStd::unordered_map<AZ::EntityId, AZStd::vector<EntityPtr>>& parentIdToChildren)
|
||||
{
|
||||
|
||||
// Find name to use in warning message
|
||||
@@ -153,16 +154,22 @@ namespace AzToolsFramework::Prefab::SpawnableUtils
|
||||
parentFromLoopId.ToString().c_str());
|
||||
}
|
||||
|
||||
|
||||
void SortEntitiesByTransformHierarchy(AzFramework::Spawnable& spawnable)
|
||||
{
|
||||
auto& entities = spawnable.GetEntities();
|
||||
SortEntitiesByTransformHierarchy(spawnable.GetEntities());
|
||||
}
|
||||
|
||||
template<typename EntityPtr>
|
||||
void SortEntitiesByTransformHierarchy(AZStd::vector<EntityPtr>& entities)
|
||||
{
|
||||
const size_t originalEntityCount = entities.size();
|
||||
|
||||
// IDs of those present in 'entities'. Does not include parent ID if parent not found in 'entities'
|
||||
AZStd::unordered_set<AZ::EntityId> existingEntityIds;
|
||||
|
||||
// map children by their parent ID (even if parent not found in 'entities')
|
||||
AZStd::unordered_map<AZ::EntityId, AzFramework::Spawnable::EntityList> parentIdToChildren;
|
||||
AZStd::unordered_map<AZ::EntityId, AZStd::vector<EntityPtr>> parentIdToChildren;
|
||||
|
||||
// use 'candidateIds' to track the parent IDs we're going to process next.
|
||||
AZStd::vector<AZ::EntityId> candidateIds;
|
||||
@@ -199,8 +206,7 @@ namespace AzToolsFramework::Prefab::SpawnableUtils
|
||||
for (auto& child : foundChildren->second)
|
||||
{
|
||||
candidateIds.push_back(child->GetId());
|
||||
entities.emplace_back(nullptr);
|
||||
entities.back().swap(child);
|
||||
entities.emplace_back(AZStd::move(child));
|
||||
}
|
||||
|
||||
parentIdToChildren.erase(foundChildren);
|
||||
|
||||
@@ -16,4 +16,11 @@ namespace AzToolsFramework::Prefab::SpawnableUtils
|
||||
bool CreateSpawnable(AzFramework::Spawnable& spawnable, const PrefabDom& prefabDom, AZStd::vector<AZ::Data::Asset<AZ::Data::AssetData>>& referencedAssets);
|
||||
|
||||
void SortEntitiesByTransformHierarchy(AzFramework::Spawnable& spawnable);
|
||||
|
||||
template <typename EntityPtr>
|
||||
void SortEntitiesByTransformHierarchy(AZStd::vector<EntityPtr>& entities);
|
||||
|
||||
// Explicit specializations
|
||||
template void SortEntitiesByTransformHierarchy(AZStd::vector<AZ::Entity*>& entities);
|
||||
template void SortEntitiesByTransformHierarchy(AZStd::vector<AZStd::unique_ptr<AZ::Entity>>& entities);
|
||||
} // namespace AzToolsFramework::Prefab::SpawnableUtils
|
||||
|
||||
Reference in New Issue
Block a user