Fixed GetComponent bug which would create invalid components if the entity didn't have the requested component

This commit is contained in:
2014-04-28 16:16:03 +02:00
parent 7da030d8cd
commit 6ba50c2d1e
+10 -1
View File
@@ -138,7 +138,16 @@ std::shared_ptr<T> World::AddComponent(EntityID entity, std::string componentTyp
template <class T>
T* World::GetComponent(EntityID entity, std::string componentType)
{
return (T*)m_EntityComponents[entity][componentType].get();
auto components = m_EntityComponents[entity];
auto it = components.find(componentType);
if (it != components.end())
{
return static_cast<T*>(it->second.get());
}
else
{
return nullptr;
}
}
#endif // World_h__