{ }Blueprint → C++

Unreal Engine 5 · Blueprint → C++

Get Component By Class in Unreal Engine 5 C++UE Docs

The Get Component By Class node maps to the templated AActor::FindComponentByClass<T>(), which returns the first component of the requested type on an Actor, or nullptr if none exists.

Blueprint node & C++ equivalent

C++
UStaticMeshComponent* Mesh = FindComponentByClass<UStaticMeshComponent>();

The C++ equivalent

Call FindComponentByClass<UStaticMeshComponent>() on an Actor to get a typed pointer back, as in UStaticMeshComponent* Mesh = FindComponentByClass<UStaticMeshComponent>(). The template argument is the component class you want, and the return value is already cast to that type, so no manual Cast is needed.

Because the result can be nullptr, check it before use to avoid dereferencing an empty pointer.

When to use it in C++

Use FindComponentByClass when you do not hold a direct pointer to the component, for instance when working with an Actor passed in from elsewhere. If multiple components share the type, it returns only the first match; use GetComponents to gather them all.

For best performance, cache the result rather than searching every frame.

Frequently asked questions

What is the C++ equivalent of Get Component By Class?+

It is the templated AActor::FindComponentByClass<T>(), which returns the first component of type T on the Actor.

What does FindComponentByClass return if there is no match?+

It returns nullptr. Always null-check the result before dereferencing the pointer.

Related Components nodes

View all Components nodes →