@@ -252,6 +252,10 @@ namespace CsvSpawner::CsvSpawnerUtils
252
252
}
253
253
}
254
254
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
+
255
259
for (const auto & entityConfig : entitiesToSpawn)
256
260
{
257
261
if (!spawnableAssetConfiguration.contains (entityConfig.m_name ))
@@ -317,7 +321,7 @@ namespace CsvSpawner::CsvSpawnerUtils
317
321
transformInterface->SetWorldTM (transform);
318
322
};
319
323
optionalArgs.m_completionCallback =
320
- [parentId, &spawnStatusCode](
324
+ [parentId, &spawnStatusCode, &broadcastSpawnInfo, &tickets, totalTickets, &completedTickets ](
321
325
[[maybe_unused]] AzFramework::EntitySpawnTicket::Id ticketId, AzFramework::SpawnableConstEntityContainerView view)
322
326
{
323
327
if (view.empty ())
@@ -329,16 +333,28 @@ namespace CsvSpawner::CsvSpawnerUtils
329
333
}
330
334
const AZ::Entity* root = *view.begin ();
331
335
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
+ }
332
343
};
333
344
optionalArgs.m_priority = AzFramework::SpawnablePriority_Lowest;
334
345
spawner->SpawnAllEntities (ticket, optionalArgs);
335
346
tickets[entityConfig.m_id ] = AZStd::move (ticket);
347
+
348
+ totalTickets++;
336
349
}
337
350
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
+ }
342
358
343
359
return tickets;
344
360
}
0 commit comments