AActor::K2_GetComponentsByClass
#include "GameFramework/Actor.h"
Access: public
Specifiers: UFUNCTIONBlueprintCallable
Description
Returns all components on this actor that are of or derive from ComponentClass. This is the Blueprint-callable version; in C++ prefer the templated GetComponents<T>() for type-safe, zero-allocation iteration.
Caveats & Gotchas
- • This method allocates and returns a TArray on every call — avoid calling it in Tick. In C++, use GetComponents<T>(OutArray) instead which fills an existing array without the Blueprint wrapper overhead.
- • The returned array contains UActorComponent* base pointers; you must cast them yourself in C++ unless you use the Blueprint node which handles output type pinning via DeterminesOutputType metadata.
- • Does not search components on child actors or attached actors; it only queries components registered to this actor.
Signature
ENGINE_API TArray<UActorComponent*> K2_GetComponentsByClass(TSubclassOf<UActorComponent> ComponentClass) const Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| ComponentClass | TSubclassOf<UActorComponent> | The class (or subclass) of component to search for. | — |
Return Type
TArray<UActorComponent*> Examples
Hide all Static Mesh Components on this actor
Blueprint
Get all mesh components (Blueprint-callable pattern) C++
// Blueprint-style: returns array of base pointers, cast needed
TArray<UActorComponent*> Meshes = K2_GetComponentsByClass(UStaticMeshComponent::StaticClass());
for (UActorComponent* Comp : Meshes)
{
Cast<UStaticMeshComponent>(Comp)->SetVisibility(false);
}
// Preferred C++ pattern (no allocation):
TArray<UStaticMeshComponent*> MeshComps;
GetComponents<UStaticMeshComponent>(MeshComps);
for (UStaticMeshComponent* Mesh : MeshComps)
{
Mesh->SetVisibility(false);
} Tags
Version History
Introduced in: 4.8
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?