Entity.AddComponent<T> method

template<typename T, typename... Args> T& AddComponent(Args&&... args);

Description

Constructs a component of type T in place on this entity, forwarding any constructor arguments. Returns a reference to the freshly-added component so you can configure it immediately. If the entity already has T, this overload asserts — use AddOrReplaceComponent<T> for idempotent behaviour.

Type parameters

TcomponentComponent type to attach.
Args…forwardArguments forwarded to the component constructor.

Returns

T&referenceThe newly-created component.

Example

auto& rb = e.AddComponent<Thread::RigidBodyComponent>();
rb.Mass = 5.0f;
rb.Friction = 0.6f;

e.AddComponent<Thread::PrimitiveComponent>(Thread::PrimitiveType::Cube);

See also

GetComponent · HasComponent

Entity.AddComponent<T> metoda

template<typename T, typename... Args> T& AddComponent(Args&&... args);

Opis

Tworzy na tej encji komponent typu T, przekazując argumenty do jego konstruktora. Zwraca referencję do nowo dodanego komponentu, więc możesz go od razu skonfigurować. Jeśli encja ma już T, ta wersja zgłasza asercję — dla zachowania idempotentnego użyj AddOrReplaceComponent<T>.

Parametry typu

TkomponentTyp komponentu do podpięcia.
Args…przekazanieArgumenty przekazywane do konstruktora komponentu.

Zwraca

T&referencjaNowo utworzony komponent.

Przykład

auto& rb = e.AddComponent<Thread::RigidBodyComponent>();
rb.Mass = 5.0f;
rb.Friction = 0.6f;

e.AddComponent<Thread::PrimitiveComponent>(Thread::PrimitiveType::Cube);

Zobacz też

GetComponent · HasComponent