Correction in set hierarchy entity logic.

Signed-off-by: AMZN-Olex <5432499+AMZN-Olex@users.noreply.github.com>
monroegm-disable-blank-issue-2
AMZN-Olex 4 years ago
parent e867aa2940
commit a2592e9ff8

@ -148,25 +148,21 @@ namespace Multiplayer
m_networkHierarchyChangedEvent.Signal(m_rootEntity->GetId()); m_networkHierarchyChangedEvent.Signal(m_rootEntity->GetId());
} }
} }
else else if ((previousHierarchyRoot && m_rootEntity == previousHierarchyRoot) || !previousHierarchyRoot)
{ {
if (m_rootEntity == previousHierarchyRoot || !previousHierarchyRoot) m_rootEntity = nullptr;
{
m_rootEntity = nullptr;
if (HasController() && GetNetBindComponent()->GetNetEntityRole() == NetEntityRole::Authority) if (HasController() && GetNetBindComponent()->GetNetEntityRole() == NetEntityRole::Authority)
{ {
NetworkHierarchyChildComponentController* controller = static_cast<NetworkHierarchyChildComponentController*>(GetController()); NetworkHierarchyChildComponentController* controller = static_cast<NetworkHierarchyChildComponentController*>(GetController());
controller->SetHierarchyRoot(InvalidNetEntityId); controller->SetHierarchyRoot(InvalidNetEntityId);
} }
GetNetBindComponent()->SetOwningConnectionId(m_previousOwningConnectionId); GetNetBindComponent()->SetOwningConnectionId(m_previousOwningConnectionId);
m_networkHierarchyLeaveEvent.Signal(); m_networkHierarchyLeaveEvent.Signal();
NotifyChildrenHierarchyDisbanded(); NotifyChildrenHierarchyDisbanded();
}
} }
} }
void NetworkHierarchyChildComponent::SetOwningConnectionId(AzNetworking::ConnectionId connectionId) void NetworkHierarchyChildComponent::SetOwningConnectionId(AzNetworking::ConnectionId connectionId)

@ -325,36 +325,36 @@ namespace Multiplayer
{ {
if (newHierarchyRoot) if (newHierarchyRoot)
{ {
m_rootEntity = newHierarchyRoot; if (m_rootEntity != newHierarchyRoot)
if (HasController() && GetNetBindComponent()->GetNetEntityRole() == NetEntityRole::Authority)
{
NetworkHierarchyChildComponentController* controller = static_cast<NetworkHierarchyChildComponentController*>(GetController());
const NetEntityId netRootId = GetNetworkEntityManager()->GetNetEntityIdById(m_rootEntity->GetId());
controller->SetHierarchyRoot(netRootId);
}
GetNetBindComponent()->SetOwningConnectionId(m_rootEntity->FindComponent<NetBindComponent>()->GetOwningConnectionId());
}
else
{
if (previousHierarchyRoot && m_rootEntity == previousHierarchyRoot || !previousHierarchyRoot)
{ {
m_rootEntity = nullptr; m_rootEntity = newHierarchyRoot;
if (HasController() && GetNetBindComponent()->GetNetEntityRole() == NetEntityRole::Authority) if (HasController() && GetNetBindComponent()->GetNetEntityRole() == NetEntityRole::Authority)
{ {
NetworkHierarchyChildComponentController* controller = static_cast<NetworkHierarchyChildComponentController*>(GetController()); NetworkHierarchyRootComponentController* controller = static_cast<NetworkHierarchyRootComponentController*>(GetController());
const NetEntityId netRootId = GetNetworkEntityManager()->GetNetEntityIdById(m_rootEntity->GetId());
controller->SetHierarchyRoot(InvalidNetEntityId); controller->SetHierarchyRoot(netRootId);
} }
GetNetBindComponent()->SetOwningConnectionId(m_previousOwningConnectionId); GetNetBindComponent()->SetOwningConnectionId(m_rootEntity->FindComponent<NetBindComponent>()->GetOwningConnectionId());
m_networkHierarchyChangedEvent.Signal(m_rootEntity->GetId());
}
}
else if ((previousHierarchyRoot && m_rootEntity == previousHierarchyRoot) || !previousHierarchyRoot)
{
m_rootEntity = nullptr;
// We lost the parent hierarchical entity, so as a root we need to re-build our own hierarchy. if (HasController() && GetNetBindComponent()->GetNetEntityRole() == NetEntityRole::Authority)
RebuildHierarchy(); {
NetworkHierarchyRootComponentController* controller = static_cast<NetworkHierarchyRootComponentController*>(GetController());
controller->SetHierarchyRoot(InvalidNetEntityId);
} }
GetNetBindComponent()->SetOwningConnectionId(m_previousOwningConnectionId);
m_networkHierarchyLeaveEvent.Signal();
// We lost the parent hierarchical entity, so as a root we need to re-build our own hierarchy.
RebuildHierarchy();
} }
} }

Loading…
Cancel
Save