Function remove_if_exists

Synopsis

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

template <typename... Component>
size_type remove_if_exists(const entity_type entity)

Description

Removes the given components from an entity.

Equivalent to the following snippet (pseudocode):

if(registry.has<Component>(entity)) { registry.remove<Component>(entity) }

Prefer this function anyway because it has slightly better performance.

Warning
Attempting to use an invalid entity results in undefined behavior.
Template Parameters

Component - Types of components to remove.

Parameters

entity - A valid entity identifier.

Return
The number of components actually removed.

Source

Lines 734-741 in src/entt/entity/registry.hpp.

template<typename... Component>
size_type remove_if_exists(const entity_type entity) {
    ENTT_ASSERT(valid(entity));
    return ([this, entity](auto &&cpool) {
        return cpool.contains(entity) ? (cpool.remove(*this, entity), true) : false;
    }(assure<Component>()) + ... + size_type{});
}





Add Discussion

Log in to comment