diff --git a/include/Engine/Core/World.h b/include/Engine/Core/World.h index 1ea17a7b..0a121728 100644 --- a/include/Engine/Core/World.h +++ b/include/Engine/Core/World.h @@ -16,7 +16,8 @@ public: EntityID CreateEntity(EntityID parent = 0); // Delete entity and all components within void DeleteEntity(EntityID entity); - + // Check if an entity exists + bool ValidEntity(EntityID entity) const; // Register a component type and allocate space for it void RegisterComponent(ComponentInfo& ci); // Attach a component to an entity and fill it with default values diff --git a/src/Engine/Core/World.cpp b/src/Engine/Core/World.cpp index 9202be12..c94cb8b3 100644 --- a/src/Engine/Core/World.cpp +++ b/src/Engine/Core/World.cpp @@ -54,6 +54,11 @@ void World::DeleteEntity(EntityID entity) m_EntityNames.erase(entity); } +bool World::ValidEntity(EntityID entity) const +{ + return m_EntityParents.find(entity) != m_EntityParents.end(); +} + void World::RegisterComponent(ComponentInfo& ci) { if (m_ComponentPools.find(ci.Name) == m_ComponentPools.end()) { @@ -75,7 +80,6 @@ ComponentWrapper World::AttachComponent(EntityID entity, std::string componentTy return c; } - bool World::HasComponent(EntityID entity, std::string componentType) const { ComponentPool* pool = m_ComponentPools.at(componentType); @@ -88,7 +92,6 @@ ComponentWrapper World::GetComponent(EntityID entity, std::string componentType) return pool->GetByEntity(entity); } - void World::DeleteComponent(EntityID entity, std::string componentType) { ComponentPool* pool = m_ComponentPools.at(componentType); @@ -102,13 +105,11 @@ const ComponentPool* World::GetComponents(std::string componentType) return (it != m_ComponentPools.end()) ? it->second : nullptr; } - EntityID World::GetParent(EntityID entity) { return m_EntityParents.at(entity); } - void World::SetParent(EntityID entity, EntityID parent) { EntityID lastParent = m_EntityParents.at(entity); diff --git a/src/Engine/Editor/EditorSystem.cpp b/src/Engine/Editor/EditorSystem.cpp index 4ceba0fd..65d9c52b 100644 --- a/src/Engine/Editor/EditorSystem.cpp +++ b/src/Engine/Editor/EditorSystem.cpp @@ -622,7 +622,7 @@ bool EditorSystem::createEntityNode(World* world, EntityID entity) if (ImGui::Button("Delete")) { world->DeleteEntity(entity); ImGui::CloseCurrentPopup(); - if (m_Selection == entity) { + if (!world->ValidEntity(m_Selection)) { m_Selection = EntityID_Invalid; } }