Skip to content

Commit 687aff9

Browse files
committed
add counter to track if all entities are spawned
Signed-off-by: Wojciech Czerski <[email protected]>
1 parent 896f067 commit 687aff9

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

Gems/CsvSpawner/Code/Source/CsvSpawner/CsvSpawnerUtils.cpp

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,10 @@ namespace CsvSpawner::CsvSpawnerUtils
252252
}
253253
}
254254

255+
// Track how many tickets are spawned and how many have completed
256+
size_t totalTickets = 0;
257+
std::atomic_size_t completedTickets = 0;
258+
255259
for (const auto& entityConfig : entitiesToSpawn)
256260
{
257261
if (!spawnableAssetConfiguration.contains(entityConfig.m_name))
@@ -317,7 +321,7 @@ namespace CsvSpawner::CsvSpawnerUtils
317321
transformInterface->SetWorldTM(transform);
318322
};
319323
optionalArgs.m_completionCallback =
320-
[parentId, &spawnStatusCode](
324+
[parentId, &spawnStatusCode, &broadcastSpawnInfo, &tickets, totalTickets, &completedTickets](
321325
[[maybe_unused]] AzFramework::EntitySpawnTicket::Id ticketId, AzFramework::SpawnableConstEntityContainerView view)
322326
{
323327
if (view.empty())
@@ -329,16 +333,28 @@ namespace CsvSpawner::CsvSpawnerUtils
329333
}
330334
const AZ::Entity* root = *view.begin();
331335
AZ::TransformBus::Event(root->GetId(), &AZ::TransformBus::Events::SetParent, parentId);
336+
337+
completedTickets++;
338+
if (completedTickets == totalTickets)
339+
{
340+
// Call CsvSpawner EBus notification - Finished
341+
CsvSpawnerNotificationBus::Broadcast(&CsvSpawnerInterface::OnEntitiesSpawnFinished, broadcastSpawnInfo, spawnStatusCode);
342+
}
332343
};
333344
optionalArgs.m_priority = AzFramework::SpawnablePriority_Lowest;
334345
spawner->SpawnAllEntities(ticket, optionalArgs);
335346
tickets[entityConfig.m_id] = AZStd::move(ticket);
347+
348+
totalTickets++;
336349
}
337350

338-
// Check is success spawn
339-
tickets.empty() ? spawnStatusCode |= SpawnStatus::Fail : spawnStatusCode |= SpawnStatus::Success;
340-
// Call CsvSpawner EBus notification - Finished
341-
CsvSpawnerNotificationBus::Broadcast(&CsvSpawnerInterface::OnEntitiesSpawnFinished, broadcastSpawnInfo, spawnStatusCode);
351+
// If no tickets were created at all (no entities spawned), send finish immediately
352+
if (totalTickets == 0)
353+
{
354+
spawnStatusCode |= SpawnStatus::Fail;
355+
// Call CsvSpawner EBus notification - Finished
356+
CsvSpawnerNotificationBus::Broadcast(&CsvSpawnerInterface::OnEntitiesSpawnFinished, broadcastSpawnInfo, spawnStatusCode);
357+
}
342358

343359
return tickets;
344360
}

0 commit comments

Comments
 (0)