Removed Component event now runs after the component has been removed from the sparse set

This commit is contained in:
maverickdgg 2022-11-01 14:21:43 +08:00
parent a9c1bd7e7a
commit d5cadfe8ed
1 changed files with 12 additions and 6 deletions

View File

@ -33,19 +33,19 @@ namespace SHADE
return;
}
std::vector<SHComponentRemovedEvent> eventVec;
for (uint32_t i = 0; i < componentSet.Size(); ++i)
{
SHComponent* comp = (SHComponent*) componentSet.GetElement(i, EntityHandleGenerator::GetIndex(entityID));
if (comp)
{
comp->OnDestroy();
SHComponentRemovedEvent eventData;
eventData.eid = entityID;
eventData.removedComponentType = i;
eventVec.push_back(eventData);
}
SHComponentRemovedEvent eventData;
eventData.eid = entityID;
eventData.removedComponentType = i;
SHEventManager::BroadcastEvent<SHComponentRemovedEvent>(eventData, SH_COMPONENT_REMOVED_EVENT);
}
@ -57,6 +57,12 @@ namespace SHADE
componentSet.RemoveElements(EntityHandleGenerator::GetIndex(entityID));
for (auto& eventData : eventVec)
{
SHEventManager::BroadcastEvent<SHComponentRemovedEvent>(eventData, SH_COMPONENT_REMOVED_EVENT);
}
//entityHandle.RemoveHandle(entityID);