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

This commit is contained in:
Stiffly
2014-04-28 16:18:08 +02:00
parent 04962155e3
commit 0b8a3230c3
+10 -1
View File
@@ -135,7 +135,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__