Function get

Synopsis

#include <src/entt/entity/group.hpp>

template <typename... Component>
decltype(auto) get(const entity_type entt) const

Description

Returns the components assigned to the given entity.

Prefer this function instead of registry::get during iterations. It has far better performance than its counterpart.

Warning
Attempting to use an invalid component type results in a compilation error. Attempting to use an entity that doesn't belong to the group results in undefined behavior.
Template Parameters

Component - Types of components to get.

Parameters

entt - A valid entity identifier.

Return
The components assigned to the entity.

Source

Lines 807-818 in src/entt/entity/group.hpp.

template<typename... Component>
[[nodiscard]] decltype(auto) get(const entity_type entt) const {
    ENTT_ASSERT(contains(entt));
    if constexpr(sizeof...(Component) == 0) {
        return std::tuple_cat(get_as_tuple(*std::get<storage_type<Owned> *>(pools), entt)..., get_as_tuple(*std::get<storage_type<Get> *>(pools), entt)...);
    } else if constexpr(sizeof...(Component) == 1) {
        return (std::get<storage_type<Component> *>(pools)->get(entt), ...);
    } else {
        return std::tuple_cat(get_as_tuple(*std::get<storage_type<Component> *>(pools), entt)...);
    }
}





Add Discussion

Log in to comment