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
| T | component | Component type to attach. |
| Args… | forward | Arguments forwarded to the component constructor. |
Returns
| T& | reference | The 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
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
| T | komponent | Typ komponentu do podpięcia. |
| Args… | przekazanie | Argumenty przekazywane do konstruktora komponentu. |
Zwraca
| T& | referencja | Nowo 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);