Entity.GetComponent<T> method
template<typename T>
T& GetComponent();
Description
Returns a reference to the component of type T attached to this
entity. Mutations through the reference are reflected immediately in serialization
and rendering.
Important: calling
GetComponent<T>() when T isn't attached triggers
an EnTT assertion in Debug and is UB in Release. Use
HasComponent<T>() first when the
presence isn't guaranteed.Type parameters
| T | component | Any registered component type (e.g. TransformComponent). |
Returns
| T& | reference | Mutable reference to the existing component. |
Example
void OnUpdate(float ts) override {
auto& tc = GetComponent<Thread::TransformComponent>();
tc.Rotation.y += ts; // spin around Y at 1 rad/s
}
See also
Entity.GetComponent<T> metoda
template<typename T>
T& GetComponent();
Opis
Zwraca referencję do komponentu typu T podpiętego do tej encji. Zmiany przez
referencję od razu widać w serializacji i renderowaniu.
Ważne: wywołanie
GetComponent<T>(), gdy
T nie jest podpięty, wywołuje asercję EnTT w Debug i jest niezdefiniowane w Release.
Gdy obecność nie jest pewna, najpierw użyj HasComponent<T>().Parametry typu
| T | komponent | Dowolny zarejestrowany typ komponentu (np. TransformComponent). |
Zwraca
| T& | referencja | Modyfikowalna referencja do istniejącego komponentu. |
Przykład
void OnUpdate(float ts) override {
auto& tc = GetComponent<Thread::TransformComponent>();
tc.Rotation.y += ts; // obrót wokół Y z prędkością 1 rad/s
}