Function replace

Synopsis

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

template <typename Component, typename... Args>
decltype(auto) replace(const entity_type entity, Args &&... args)

Description

Replaces the given component for an entity.

A new instance of the given component is created and initialized with the arguments provided (the component must have a proper constructor or be of aggregate type). Then the component is assigned to the given entity.

Warning
Attempting to use an invalid entity or to replace a component of an entity that doesn't own it results in undefined behavior.
Template Parameters

Component - Type of component to replace.

Args - Types of arguments to use to construct the component.

Parameters

entity - A valid entity identifier.

args - Parameters to use to initialize the component.

Return
A reference to the component being replaced.

Source

Lines 679-682 in src/entt/entity/registry.hpp.

template<typename Component, typename... Args>
decltype(auto) replace(const entity_type entity, Args &&... args) {
    return assure<Component>().patch(*this, entity, [&args...](auto &curr) { curr = Component{std::forward<Args>(args)...}; });
}





Add Discussion

Log in to comment