From 435f8396660c35b830c9df8fd7dbea8d163888d3 Mon Sep 17 00:00:00 2001 From: Sergey Pereslavtsev Date: Fri, 12 Nov 2021 13:36:14 +0000 Subject: [PATCH] Fixed IMGUI Entity Outliner to show net entities Signed-off-by: Sergey Pereslavtsev --- .../Components/TransformComponent.cpp | 2 +- .../Source/Pipeline/NetworkPrefabProcessor.cpp | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/Code/Framework/AzFramework/AzFramework/Components/TransformComponent.cpp b/Code/Framework/AzFramework/AzFramework/Components/TransformComponent.cpp index bc109b73c2..809f664a10 100644 --- a/Code/Framework/AzFramework/AzFramework/Components/TransformComponent.cpp +++ b/Code/Framework/AzFramework/AzFramework/Components/TransformComponent.cpp @@ -534,7 +534,7 @@ namespace AzFramework void TransformComponent::SetParentImpl(AZ::EntityId parentId, bool isKeepWorldTM) { - if (parentId == GetEntityId()) + if (GetEntity() && parentId == GetEntityId()) { AZ_Warning("TransformComponent", false, "An entity can not be set as its own parent."); return; diff --git a/Gems/Multiplayer/Code/Source/Pipeline/NetworkPrefabProcessor.cpp b/Gems/Multiplayer/Code/Source/Pipeline/NetworkPrefabProcessor.cpp index bec659180c..338804184c 100644 --- a/Gems/Multiplayer/Code/Source/Pipeline/NetworkPrefabProcessor.cpp +++ b/Gems/Multiplayer/Code/Source/Pipeline/NetworkPrefabProcessor.cpp @@ -53,7 +53,7 @@ namespace Multiplayer ; serializeContext->Class() - ->Version(3) + ->Version(4) ->Field("SerializationFormat", &NetworkPrefabProcessor::m_serializationFormat) ; } @@ -146,6 +146,8 @@ namespace Multiplayer networkSpawnableAsset.Create(networkSpawnable->GetId()); networkSpawnableAsset.SetAutoLoadBehavior(AZ::Data::AssetLoadBehavior::PreLoad); + AZStd::unordered_set prefabNetEntityIds; + for (auto* prefabEntity : prefabNetEntities) { Instance* instance = netEntityToInstanceMap[prefabEntity]; @@ -158,6 +160,20 @@ namespace Multiplayer netEntity->InvalidateDependencies(); netEntity->EvaluateDependencies(); + auto* transformComponent = netEntity->FindComponent(); + if (transformComponent) + { + AZ::EntityId parentId = transformComponent->GetParentId(); + if (parentId.IsValid() && !prefabNetEntityIds.contains(parentId)) + { + // Clear parent ID for net entities parented to a non-net entity. + // To be addressed by the spawnable aliases system. + transformComponent->SetParent(AZ::EntityId()); + } + } + + prefabNetEntityIds.insert(netEntity->GetId()); + // Insert the entity into the target net spawnable netSpawnableEntities.emplace_back(netEntity); }