RealDocs

AActor::K2_GetComponentsByClass

function Engine Blueprint Since 4.8
#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
Event BeginPlay Get Components by Class Target is Actor Component Class StaticMeshComponent StaticMeshComponent Return Value For Each Loop Array Loop Body Array Element Array Element Array Index Completed Set Visibility Target is Scene Component Target New Visibility false false Propagate to Sub-Components Propagate to Sub-Components false false
Edit Blueprint graph Hide all Static Mesh Components on this actor
Drag node headers to move · Drag from an output pin to an input pin to connect · Scroll to zoom · Right-click for actions
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);
}

Version History

Introduced in: 4.8

Version Status Notes
5.6 stable

Feedback

Was this helpful?

Suggest an edit

Select a field above to begin editing.