Function emplace

Synopsis

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

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

Description

Assigns the given component to 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 assign a component to an entity that already owns it results in undefined behavior.
Template Parameters

Component - Type of component to create.

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 newly created component.

Source

Lines 559-563 in src/entt/entity/registry.hpp.

template<typename Component, typename... Args>
decltype(auto) emplace(const entity_type entity, Args &&... args) {
    ENTT_ASSERT(valid(entity));
    return assure<Component>().emplace(*this, entity, std::forward<Args>(args)...);
}





Add Discussion

Log in to comment