소스 검색

asynhronous despawning

Signed-off-by: Michał Pełka <[email protected]>
Michał Pełka 5 달 전
부모
커밋
0e3c22c1e1
1개의 변경된 파일14개의 추가작업 그리고 3개의 파일을 삭제
  1. 14 3
      Gems/SimulationInterfaces/Code/Source/Clients/SimulationEntitiesManager.cpp

+ 14 - 3
Gems/SimulationInterfaces/Code/Source/Clients/SimulationEntitiesManager.cpp

@@ -445,7 +445,20 @@ namespace SimulationInterfaces
         if (m_spawnedTickets.find(ticketId) != m_spawnedTickets.end())
         if (m_spawnedTickets.find(ticketId) != m_spawnedTickets.end())
         {
         {
             // remove the ticket
             // remove the ticket
-            m_spawnedTickets.erase(ticketId);
+            //m_spawnedTickets.erase(ticketId);
+            /// get spawner
+            auto spawner = AZ::Interface<AzFramework::SpawnableEntitiesDefinition>::Get();
+            AZ_Assert(spawner, "SpawnableEntitiesDefinition is not available.");
+            // get ticket
+            auto ticket = m_spawnedTickets[ticketId];
+            // remove ticket
+            AzFramework::DespawnAllEntitiesOptionalArgs optionalArgs;
+            optionalArgs.m_completionCallback = [this, completedCb](AzFramework::EntitySpawnTicket::Id ticketId)
+            {
+                m_spawnedTickets.erase(ticketId);
+                completedCb(AZ::Success());
+            };
+            spawner->DespawnAllEntities(ticket, optionalArgs);
         }
         }
         else
         else
         {
         {
@@ -469,8 +482,6 @@ namespace SimulationInterfaces
             return true;
             return true;
         }
         }
 #endif
 #endif
-        // TODO: Mpelka: Implement deletion of entities is asynhronous way, it should be called when the entity is removed.
-        completedCb(AZ::Success());
     }
     }
 
 
     AZ::Outcome<SpawnableList, FailedResult> SimulationEntitiesManager::GetSpawnables()
     AZ::Outcome<SpawnableList, FailedResult> SimulationEntitiesManager::GetSpawnables()