CommonHierarchySetup.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project. For complete copyright and license terms please see the LICENSE at the root of this distribution.
  3. *
  4. * SPDX-License-Identifier: Apache-2.0 OR MIT
  5. *
  6. */
  7. #pragma once
  8. #include <IMultiplayerConnectionMock.h>
  9. #include <MockInterfaces.h>
  10. #include <AzCore/Component/Entity.h>
  11. #include <AzCore/EBus/EventSchedulerSystemComponent.h>
  12. #include <AzCore/Console/Console.h>
  13. #include <AzCore/Math/Vector3.h>
  14. #include <AzCore/Name/Name.h>
  15. #include <AzCore/Name/NameDictionary.h>
  16. #include <AzCore/Serialization/SerializeContext.h>
  17. #include <AzCore/UnitTest/TestTypes.h>
  18. #include <AzCore/UnitTest/UnitTest.h>
  19. #include <AzCore/UnitTest/Mocks/MockITime.h>
  20. #include <AzFramework/Components/TransformComponent.h>
  21. #include <AzNetworking/Serialization/NetworkInputSerializer.h>
  22. #include <AzNetworking/Serialization/NetworkOutputSerializer.h>
  23. #include <AzTest/AzTest.h>
  24. #include <Multiplayer/IMultiplayer.h>
  25. #include <Multiplayer/Components/NetBindComponent.h>
  26. #include <Multiplayer/Components/NetworkHierarchyChildComponent.h>
  27. #include <Multiplayer/Components/NetworkHierarchyRootComponent.h>
  28. #include <Multiplayer/Components/NetworkTransformComponent.h>
  29. #include <Multiplayer/NetworkEntity/EntityReplication/EntityReplicationManager.h>
  30. #include <Multiplayer/NetworkEntity/EntityReplication/EntityReplicator.h>
  31. #include <NetworkEntity/NetworkEntityAuthorityTracker.h>
  32. #include <NetworkEntity/NetworkEntityTracker.h>
  33. #include <Tests/TestMultiplayerComponent.h>
  34. namespace Multiplayer
  35. {
  36. using namespace testing;
  37. using namespace ::UnitTest;
  38. class NetworkHierarchyCallbacks
  39. {
  40. public:
  41. virtual ~NetworkHierarchyCallbacks() = default;
  42. virtual void OnNetworkHierarchyLeave() = 0;
  43. virtual void OnNetworkHierarchyUpdated(const AZ::EntityId& hierarchyRootId) = 0;
  44. };
  45. class MockNetworkHierarchyCallbackHandler : public NetworkHierarchyCallbacks
  46. {
  47. public:
  48. MockNetworkHierarchyCallbackHandler()
  49. : m_leaveHandler([this]() { OnNetworkHierarchyLeave(); })
  50. , m_changedHandler([this](const AZ::EntityId& rootId) { OnNetworkHierarchyUpdated(rootId); })
  51. {
  52. }
  53. NetworkHierarchyLeaveEvent::Handler m_leaveHandler;
  54. NetworkHierarchyChangedEvent::Handler m_changedHandler;
  55. MOCK_METHOD0(OnNetworkHierarchyLeave, void());
  56. MOCK_METHOD1(OnNetworkHierarchyUpdated, void(const AZ::EntityId&));
  57. };
  58. class HierarchyTests
  59. : public LeakDetectionFixture
  60. {
  61. public:
  62. void SetUp() override
  63. {
  64. AZ::NameDictionary::Create();
  65. m_mockComponentApplicationRequests = AZStd::make_unique<NiceMock<MockComponentApplicationRequests>>();
  66. AZ::Interface<AZ::ComponentApplicationRequests>::Register(m_mockComponentApplicationRequests.get());
  67. ON_CALL(*m_mockComponentApplicationRequests, AddEntity(_)).WillByDefault(Invoke(this, &HierarchyTests::AddEntity));
  68. ON_CALL(*m_mockComponentApplicationRequests, FindEntity(_)).WillByDefault(Invoke(this, &HierarchyTests::FindEntity));
  69. // register components involved in testing
  70. m_serializeContext = AZStd::make_unique<AZ::SerializeContext>();
  71. m_transformDescriptor.reset(AzFramework::TransformComponent::CreateDescriptor());
  72. m_transformDescriptor->Reflect(m_serializeContext.get());
  73. m_netBindDescriptor.reset(NetBindComponent::CreateDescriptor());
  74. m_netBindDescriptor->Reflect(m_serializeContext.get());
  75. m_hierarchyRootDescriptor.reset(NetworkHierarchyRootComponent::CreateDescriptor());
  76. m_hierarchyRootDescriptor->Reflect(m_serializeContext.get());
  77. m_hierarchyChildDescriptor.reset(NetworkHierarchyChildComponent::CreateDescriptor());
  78. m_hierarchyChildDescriptor->Reflect(m_serializeContext.get());
  79. m_netTransformDescriptor.reset(NetworkTransformComponent::CreateDescriptor());
  80. m_netTransformDescriptor->Reflect(m_serializeContext.get());
  81. m_testMultiplayerComponentDescriptor.reset(MultiplayerTest::TestMultiplayerComponent::CreateDescriptor());
  82. m_testMultiplayerComponentDescriptor->Reflect(m_serializeContext.get());
  83. m_testInputDriverComponentDescriptor.reset(MultiplayerTest::TestInputDriverComponent::CreateDescriptor());
  84. m_testInputDriverComponentDescriptor->Reflect(m_serializeContext.get());
  85. m_mockMultiplayer = AZStd::make_unique<NiceMock<MockMultiplayer>>();
  86. AZ::Interface<IMultiplayer>::Register(m_mockMultiplayer.get());
  87. EXPECT_NE(AZ::Interface<IMultiplayer>::Get(), nullptr);
  88. // Create space for replication stats
  89. // Without Multiplayer::RegisterMultiplayerComponents() the stats go to invalid id, which is fine for unit tests
  90. GetMultiplayer()->GetStats().ReserveComponentStats(Multiplayer::InvalidNetComponentId, 50, 0);
  91. m_mockNetworkEntityManager = AZStd::make_unique<NiceMock<MockNetworkEntityManager>>();
  92. AZ::Interface<INetworkEntityManager>::Register(m_mockNetworkEntityManager.get());
  93. ON_CALL(*m_mockNetworkEntityManager, AddEntityToEntityMap(_, _)).WillByDefault(Invoke(this, &HierarchyTests::AddEntityToEntityMap));
  94. ON_CALL(*m_mockNetworkEntityManager, RemoveEntityFromEntityMap(_)).WillByDefault(Invoke(this, &HierarchyTests::RemoveEntityFromEntityMap));
  95. ON_CALL(*m_mockNetworkEntityManager, GetEntity(_)).WillByDefault(Invoke(this, &HierarchyTests::GetEntity));
  96. ON_CALL(*m_mockNetworkEntityManager, GetEntityCount()).WillByDefault(Invoke(this, &HierarchyTests::GetEntityCount));
  97. ON_CALL(*m_mockNetworkEntityManager, GetNetEntityIdById(_)).WillByDefault(Invoke(this, &HierarchyTests::GetNetEntityIdById));
  98. m_mockTime = AZStd::make_unique<AZ::NiceTimeSystemMock>();
  99. m_eventScheduler = AZStd::make_unique<AZ::EventSchedulerSystemComponent>();
  100. m_mockNetworkTime = AZStd::make_unique<NiceMock<MockNetworkTime>>();
  101. AZ::Interface<INetworkTime>::Register(m_mockNetworkTime.get());
  102. ON_CALL(*m_mockMultiplayer, GetNetworkEntityManager()).WillByDefault(Return(m_mockNetworkEntityManager.get()));
  103. EXPECT_NE(AZ::Interface<IMultiplayer>::Get()->GetNetworkEntityManager(), nullptr);
  104. const IpAddress address("localhost", 1, ProtocolType::Udp);
  105. m_mockConnection = AZStd::make_unique<NiceMock<IMultiplayerConnectionMock>>(ConnectionId{ 1 }, address, ConnectionRole::Connector);
  106. m_mockConnectionListener = AZStd::make_unique<MockConnectionListener>();
  107. m_networkEntityTracker = AZStd::make_unique<NetworkEntityTracker>();
  108. ON_CALL(*m_mockNetworkEntityManager, GetNetworkEntityTracker()).WillByDefault(Return(m_networkEntityTracker.get()));
  109. m_networkEntityAuthorityTracker = AZStd::make_unique<NetworkEntityAuthorityTracker>(*m_mockNetworkEntityManager);
  110. ON_CALL(*m_mockNetworkEntityManager, GetNetworkEntityAuthorityTracker()).WillByDefault(Return(m_networkEntityAuthorityTracker.get()));
  111. m_entityReplicationManager = AZStd::make_unique<EntityReplicationManager>(*m_mockConnection, *m_mockConnectionListener, EntityReplicationManager::Mode::LocalClientToRemoteServer);
  112. m_console.reset(aznew AZ::Console());
  113. AZ::Interface<AZ::IConsole>::Register(m_console.get());
  114. m_console->LinkDeferredFunctors(AZ::ConsoleFunctorBase::GetDeferredHead());
  115. m_multiplayerComponentRegistry = AZStd::make_unique<MultiplayerComponentRegistry>();
  116. ON_CALL(*m_mockNetworkEntityManager, GetMultiplayerComponentRegistry()).WillByDefault(Return(m_multiplayerComponentRegistry.get()));
  117. RegisterMultiplayerComponents();
  118. MultiplayerTest::RegisterMultiplayerComponents();
  119. }
  120. void TearDown() override
  121. {
  122. m_multiplayerComponentRegistry.reset();
  123. AZ::Interface<AZ::IConsole>::Unregister(m_console.get());
  124. m_console.reset();
  125. m_networkEntityMap.clear();
  126. m_entities.clear();
  127. m_entityReplicationManager.reset();
  128. m_mockConnection.reset();
  129. m_mockConnectionListener.reset();
  130. m_networkEntityTracker.reset();
  131. m_networkEntityAuthorityTracker.reset();
  132. AZ::Interface<INetworkTime>::Unregister(m_mockNetworkTime.get());
  133. AZ::Interface<INetworkEntityManager>::Unregister(m_mockNetworkEntityManager.get());
  134. AZ::Interface<IMultiplayer>::Unregister(m_mockMultiplayer.get());
  135. AZ::Interface<AZ::ComponentApplicationRequests>::Unregister(m_mockComponentApplicationRequests.get());
  136. m_eventScheduler.reset();
  137. m_mockTime.reset();
  138. m_mockNetworkEntityManager.reset();
  139. m_mockMultiplayer.reset();
  140. m_testInputDriverComponentDescriptor.reset();
  141. m_testMultiplayerComponentDescriptor.reset();
  142. m_transformDescriptor.reset();
  143. m_netTransformDescriptor.reset();
  144. m_hierarchyRootDescriptor.reset();
  145. m_hierarchyChildDescriptor.reset();
  146. m_netBindDescriptor.reset();
  147. m_serializeContext.reset();
  148. m_mockComponentApplicationRequests.reset();
  149. AZ::NameDictionary::Destroy();
  150. }
  151. AZStd::unique_ptr<AZ::IConsole> m_console;
  152. AZStd::unique_ptr<NiceMock<MockComponentApplicationRequests>> m_mockComponentApplicationRequests;
  153. AZStd::unique_ptr<AZ::SerializeContext> m_serializeContext;
  154. AZStd::unique_ptr<AZ::ComponentDescriptor> m_transformDescriptor;
  155. AZStd::unique_ptr<AZ::ComponentDescriptor> m_netBindDescriptor;
  156. AZStd::unique_ptr<AZ::ComponentDescriptor> m_hierarchyRootDescriptor;
  157. AZStd::unique_ptr<AZ::ComponentDescriptor> m_hierarchyChildDescriptor;
  158. AZStd::unique_ptr<AZ::ComponentDescriptor> m_netTransformDescriptor;
  159. AZStd::unique_ptr<AZ::ComponentDescriptor> m_testMultiplayerComponentDescriptor;
  160. AZStd::unique_ptr<AZ::ComponentDescriptor> m_testInputDriverComponentDescriptor;
  161. AZStd::unique_ptr<NiceMock<MockMultiplayer>> m_mockMultiplayer;
  162. AZStd::unique_ptr<MockNetworkEntityManager> m_mockNetworkEntityManager;
  163. AZStd::unique_ptr<AZ::EventSchedulerSystemComponent> m_eventScheduler;
  164. AZStd::unique_ptr<AZ::NiceTimeSystemMock> m_mockTime;
  165. AZStd::unique_ptr<NiceMock<MockNetworkTime>> m_mockNetworkTime;
  166. AZStd::unique_ptr<NiceMock<IMultiplayerConnectionMock>> m_mockConnection;
  167. AZStd::unique_ptr<MockConnectionListener> m_mockConnectionListener;
  168. AZStd::unique_ptr<NetworkEntityTracker> m_networkEntityTracker;
  169. AZStd::unique_ptr<NetworkEntityAuthorityTracker> m_networkEntityAuthorityTracker;
  170. AZStd::unique_ptr<EntityReplicationManager> m_entityReplicationManager;
  171. AZStd::unique_ptr<MultiplayerComponentRegistry> m_multiplayerComponentRegistry;;
  172. mutable AZStd::map<NetEntityId, AZ::Entity*> m_networkEntityMap;
  173. NetworkEntityHandle AddEntityToEntityMap(NetEntityId netEntityId, AZ::Entity* entity)
  174. {
  175. m_networkEntityMap[netEntityId] = entity;
  176. return NetworkEntityHandle(entity, m_networkEntityTracker.get());
  177. }
  178. void RemoveEntityFromEntityMap(NetEntityId netEntityId)
  179. {
  180. m_networkEntityMap.erase(netEntityId);
  181. }
  182. uint32_t GetEntityCount() const
  183. {
  184. return aznumeric_cast<uint32_t>(m_networkEntityMap.size());
  185. }
  186. ConstNetworkEntityHandle GetEntity(NetEntityId netEntityId) const
  187. {
  188. AZ::Entity* entity = m_networkEntityMap[netEntityId];
  189. return ConstNetworkEntityHandle(entity, m_networkEntityTracker.get());
  190. }
  191. NetEntityId GetNetEntityIdById(const AZ::EntityId& entityId) const
  192. {
  193. for (const auto& pair : m_networkEntityMap)
  194. {
  195. if (pair.second->GetId() == entityId)
  196. {
  197. return pair.first;
  198. }
  199. }
  200. return InvalidNetEntityId;
  201. }
  202. AZStd::map<AZ::EntityId, AZ::Entity*> m_entities;
  203. bool AddEntity(AZ::Entity* entity)
  204. {
  205. m_entities[entity->GetId()] = entity;
  206. return true;
  207. }
  208. AZ::Entity* FindEntity(AZ::EntityId entityId)
  209. {
  210. const auto iterator = m_entities.find(entityId);
  211. if (iterator != m_entities.end())
  212. {
  213. return iterator->second;
  214. }
  215. return nullptr;
  216. }
  217. void SetupEntity(const AZStd::unique_ptr<AZ::Entity>& entity, NetEntityId netId, NetEntityRole role)
  218. {
  219. if (const auto netBindComponent = entity->FindComponent<Multiplayer::NetBindComponent>())
  220. {
  221. netBindComponent->PreInit(entity.get(), PrefabEntityId{ AZ::Name("test"), 1 }, netId, role);
  222. entity->Init();
  223. }
  224. }
  225. static void StopEntity(const AZStd::unique_ptr<AZ::Entity>& entity)
  226. {
  227. if (const auto netBindComponent = entity->FindComponent<Multiplayer::NetBindComponent>())
  228. {
  229. netBindComponent->StopEntity();
  230. }
  231. }
  232. static void StopAndDeactivateEntity(AZStd::unique_ptr<AZ::Entity>& entity)
  233. {
  234. if (entity)
  235. {
  236. StopEntity(entity);
  237. entity->Deactivate();
  238. entity.reset();
  239. }
  240. }
  241. void CreateEntityWithRootHierarchy(AZStd::unique_ptr<AZ::Entity>& rootEntity)
  242. {
  243. rootEntity->CreateComponent<AzFramework::TransformComponent>();
  244. rootEntity->CreateComponent<NetBindComponent>();
  245. rootEntity->CreateComponent<NetworkTransformComponent>();
  246. rootEntity->CreateComponent<NetworkHierarchyRootComponent>();
  247. }
  248. void CreateEntityWithChildHierarchy(AZStd::unique_ptr<AZ::Entity>& childEntity)
  249. {
  250. childEntity->CreateComponent<AzFramework::TransformComponent>();
  251. childEntity->CreateComponent<NetBindComponent>();
  252. childEntity->CreateComponent<NetworkTransformComponent>();
  253. childEntity->CreateComponent<NetworkHierarchyChildComponent>();
  254. }
  255. void SetParentIdOnNetworkTransform(const AZStd::unique_ptr<AZ::Entity>& entity, NetEntityId netParentId)
  256. {
  257. /* Derived from NetworkTransformComponent.AutoComponent.xml */
  258. constexpr int totalBits = 6 /*NetworkTransformComponentInternal::AuthorityToClientDirtyEnum::Count*/;
  259. constexpr int parentIdBit = 4 /*NetworkTransformComponentInternal::AuthorityToClientDirtyEnum::parentEntityId_DirtyFlag*/;
  260. ReplicationRecord currentRecord;
  261. currentRecord.m_authorityToClient.AddBits(totalBits);
  262. currentRecord.m_authorityToClient.SetBit(parentIdBit, true);
  263. constexpr uint32_t bufferSize = 100;
  264. AZStd::array<uint8_t, bufferSize> buffer = {};
  265. NetworkInputSerializer inSerializer(buffer.begin(), bufferSize);
  266. ISerializer& serializer = inSerializer;
  267. serializer.Serialize(netParentId, "parentEntityId"); // Derived from NetworkTransformComponent.AutoComponent.xml
  268. NetworkOutputSerializer outSerializer(buffer.begin(), bufferSize);
  269. ReplicationRecord notifyRecord = currentRecord;
  270. entity->FindComponent<NetworkTransformComponent>()->SerializeStateDeltaMessage(currentRecord, outSerializer);
  271. entity->FindComponent<NetworkTransformComponent>()->NotifyStateDeltaChanges(notifyRecord);
  272. }
  273. void SetTranslationOnNetworkTransform(const AZStd::unique_ptr<AZ::Entity>& entity, AZ::Vector3 translation)
  274. {
  275. /* Derived from NetworkTransformComponent.AutoComponent.xml */
  276. constexpr int totalBits = 6 /*NetworkTransformComponentInternal::AuthorityToClientDirtyEnum::Count*/;
  277. constexpr int translationBit = 1 /*NetworkTransformComponentInternal::AuthorityToClientDirtyEnum::translation_DirtyFlag*/;
  278. ReplicationRecord currentRecord;
  279. currentRecord.m_authorityToClient.AddBits(totalBits);
  280. currentRecord.m_authorityToClient.SetBit(translationBit, true);
  281. constexpr uint32_t bufferSize = 100;
  282. AZStd::array<uint8_t, bufferSize> buffer = {};
  283. NetworkInputSerializer inSerializer(buffer.begin(), bufferSize);
  284. static_cast<ISerializer*>(&inSerializer)->Serialize(translation,
  285. "translation" /* Derived from NetworkTransformComponent.AutoComponent.xml */);
  286. NetworkOutputSerializer outSerializer(buffer.begin(), bufferSize);
  287. ReplicationRecord notifyRecord = currentRecord;
  288. entity->FindComponent<NetworkTransformComponent>()->SerializeStateDeltaMessage(currentRecord, outSerializer);
  289. entity->FindComponent<NetworkTransformComponent>()->NotifyStateDeltaChanges(notifyRecord);
  290. }
  291. template <typename Component>
  292. void SetHierarchyRootFieldOnNetworkHierarchyChild(const AZStd::unique_ptr<AZ::Entity>& entity, NetEntityId value)
  293. {
  294. /* Derived from NetworkHierarchyChildComponent.AutoComponent.xml */
  295. constexpr int totalBits = 1 /*NetworkHierarchyChildComponentInternal::AuthorityToClientDirtyEnum::Count*/;
  296. constexpr int inHierarchyBit = 0 /*NetworkHierarchyChildComponentInternal::AuthorityToClientDirtyEnum::hierarchyRoot_DirtyFlag*/;
  297. ReplicationRecord currentRecord;
  298. currentRecord.m_authorityToClient.AddBits(totalBits);
  299. currentRecord.m_authorityToClient.SetBit(inHierarchyBit, true);
  300. constexpr uint32_t bufferSize = 100;
  301. AZStd::array<uint8_t, bufferSize> buffer = {};
  302. NetworkInputSerializer inSerializer(buffer.begin(), bufferSize);
  303. ISerializer& serializer = inSerializer;
  304. serializer.Serialize(value, "hierarchyRoot"); // Derived from NetworkHierarchyChildComponent.AutoComponent.xml
  305. NetworkOutputSerializer outSerializer(buffer.begin(), bufferSize);
  306. ReplicationRecord notifyRecord = currentRecord;
  307. entity->FindComponent<Component>()->SerializeStateDeltaMessage(currentRecord, outSerializer);
  308. entity->FindComponent<Component>()->NotifyStateDeltaChanges(notifyRecord);
  309. }
  310. struct EntityInfo
  311. {
  312. enum class Role
  313. {
  314. Root,
  315. Child,
  316. None
  317. };
  318. EntityInfo(AZ::u64 entityId, const char* entityName, NetEntityId netId, Role role)
  319. : m_entity(AZStd::make_unique<AZ::Entity>(AZ::EntityId(entityId), entityName))
  320. , m_netId(netId)
  321. , m_role(role)
  322. {
  323. }
  324. ~EntityInfo()
  325. {
  326. StopAndDeactivateEntity(m_entity);
  327. }
  328. AZStd::unique_ptr<AZ::Entity> m_entity;
  329. NetEntityId m_netId;
  330. AZStd::unique_ptr<EntityReplicator> m_replicator;
  331. Role m_role = Role::None;
  332. };
  333. void PopulateHierarchicalEntity(const EntityInfo& entityInfo)
  334. {
  335. entityInfo.m_entity->CreateComponent<AzFramework::TransformComponent>();
  336. entityInfo.m_entity->CreateComponent<NetBindComponent>();
  337. entityInfo.m_entity->CreateComponent<NetworkTransformComponent>();
  338. entityInfo.m_entity->CreateComponent<MultiplayerTest::TestMultiplayerComponent>();
  339. entityInfo.m_entity->CreateComponent<MultiplayerTest::TestInputDriverComponent>();
  340. switch (entityInfo.m_role)
  341. {
  342. case EntityInfo::Role::Root:
  343. entityInfo.m_entity->CreateComponent<NetworkHierarchyRootComponent>();
  344. break;
  345. case EntityInfo::Role::Child:
  346. entityInfo.m_entity->CreateComponent<NetworkHierarchyChildComponent>();
  347. break;
  348. case EntityInfo::Role::None:
  349. break;
  350. }
  351. }
  352. void CreateDeepHierarchy(EntityInfo& root, EntityInfo& child, EntityInfo& childOfChild)
  353. {
  354. PopulateHierarchicalEntity(root);
  355. PopulateHierarchicalEntity(child);
  356. PopulateHierarchicalEntity(childOfChild);
  357. SetupEntity(root.m_entity, root.m_netId, NetEntityRole::Authority);
  358. SetupEntity(child.m_entity, child.m_netId, NetEntityRole::Authority);
  359. SetupEntity(childOfChild.m_entity, childOfChild.m_netId, NetEntityRole::Authority);
  360. // Create an entity replicator for the child entity
  361. const NetworkEntityHandle childOfChildHandle(childOfChild.m_entity.get(), m_networkEntityTracker.get());
  362. childOfChild.m_replicator = AZStd::make_unique<EntityReplicator>(*m_entityReplicationManager, m_mockConnection.get(), NetEntityRole::Client, childOfChildHandle);
  363. childOfChild.m_replicator->Initialize(childOfChildHandle);
  364. // Create an entity replicator for the child entity
  365. const NetworkEntityHandle childHandle(child.m_entity.get(), m_networkEntityTracker.get());
  366. child.m_replicator = AZStd::make_unique<EntityReplicator>(*m_entityReplicationManager, m_mockConnection.get(), NetEntityRole::Client, childHandle);
  367. child.m_replicator->Initialize(childHandle);
  368. // Create an entity replicator for the root entity
  369. const NetworkEntityHandle rootHandle(root.m_entity.get(), m_networkEntityTracker.get());
  370. root.m_replicator = AZStd::make_unique<EntityReplicator>(*m_entityReplicationManager, m_mockConnection.get(), NetEntityRole::Client, rootHandle);
  371. root.m_replicator->Initialize(rootHandle);
  372. root.m_entity->Activate();
  373. child.m_entity->Activate();
  374. childOfChild.m_entity->Activate();
  375. }
  376. };
  377. }