mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2024-11-10 02:08:20 +00:00
Merge pull request #585 Fix child entities not being removed from their parents correctly on deletion
Fix child entities not being removed from their parents correctly on deletion
This commit is contained in:
commit
2403a7fe45
@ -125,6 +125,9 @@ Entity::~Entity() {
|
||||
|
||||
m_Components.erase(pair.first);
|
||||
}
|
||||
if (m_ParentEntity) {
|
||||
m_ParentEntity->RemoveChild(this);
|
||||
}
|
||||
}
|
||||
|
||||
void Entity::Initialize()
|
||||
@ -1656,6 +1659,17 @@ void Entity::AddChild(Entity* child) {
|
||||
m_ChildEntities.push_back(child);
|
||||
}
|
||||
|
||||
void Entity::RemoveChild(Entity* child) {
|
||||
if (!child) return;
|
||||
for (auto entity = m_ChildEntities.begin(); entity != m_ChildEntities.end(); entity++) {
|
||||
if (*entity && (*entity)->GetObjectID() == child->GetObjectID()) {
|
||||
m_IsParentChildDirty = true;
|
||||
m_ChildEntities.erase(entity);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Entity::AddTimer(std::string name, float time) {
|
||||
EntityTimer* timer = new EntityTimer(name, time);
|
||||
m_Timers.push_back(timer);
|
||||
|
@ -143,6 +143,7 @@ public:
|
||||
void SetProximityRadius(dpEntity* entity, std::string name);
|
||||
|
||||
void AddChild(Entity* child);
|
||||
void RemoveChild(Entity* child);
|
||||
void AddTimer(std::string name, float time);
|
||||
void AddCallbackTimer(float time, std::function<void()> callback);
|
||||
bool HasTimer(const std::string& name);
|
||||
|
Loading…
Reference in New Issue
Block a user