diff --git a/SHADE_Engine/src/ECS_Base/Managers/SHComponentManager.h b/SHADE_Engine/src/ECS_Base/Managers/SHComponentManager.h index 8921fbce..9fcbf6f8 100644 --- a/SHADE_Engine/src/ECS_Base/Managers/SHComponentManager.h +++ b/SHADE_Engine/src/ECS_Base/Managers/SHComponentManager.h @@ -23,7 +23,7 @@ #include "SH_API.h" #include "Events/SHEventManager.hpp" - +#include #include namespace SHADE @@ -151,6 +151,32 @@ namespace SHADE return (componentSet.GetSparseSet()->GetElement_s(EntityHandleGenerator::GetIndex(entityID))); } + /*!************************************************************************* + * \brief + * Gets the Component of the entity with the specified entityID + * + * This is the safe version of GetComponent_s which does a HasComponent to make + * sure that the entity has such a component and returns nullptr if it doesn't + * + * This safe version also checks if the sparse set of this component type + * has been created in SHComponentManager and creates one if it doesn't + * + * @tparam T... + * Pack of Types for all the Components to get. + * \param entityID + * EntityID of the entity that we are trying to get the component of. + * \return + * A tuple of pointers to all the components specified. + * Returns nullptr if the entity does not contain such a component. + ***************************************************************************/ + + template + static std::enable_if_t<(... && std::is_base_of_v), std::tuple> GetComponents(EntityID entityID) noexcept + { + return std::make_tuple(GetComponent_s(entityID)...); + } + + /*!************************************************************************* * \brief * Gets the Component of the entity with the specified entityID