AActor::GetComponentsByClass
#include "GameFramework/Actor.h"
Access: public
Specifiers: UFUNCTIONBlueprintCallable
Description
Returns all components of the given class attached to this actor. In C++ prefer the templated `GetComponents<T>(OutArray)` which avoids allocating a new array and skips the cast.
Signature
TArray<UActorComponent*> K2_GetComponentsByClass(TSubclassOf<UActorComponent> ComponentClass) const Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| ComponentClass | TSubclassOf<UActorComponent> | The class of components to search for. | — |
Return Type
TArray<UActorComponent*> Caveats & Gotchas
- • The Blueprint-exposed version (K2_GetComponentsByClass) returns a new TArray each call. In C++, call GetComponents<T>(TArray<T*>&) to fill an existing array instead — it's faster and avoids the copy.
- • Does not recurse into child actors. Child actor components are separate actors with their own component arrays.
Example
Get all mesh components in C++ C++
TArray<UStaticMeshComponent*> Meshes;
GetComponents<UStaticMeshComponent>(Meshes);
for (UStaticMeshComponent* Mesh : Meshes)
{
Mesh->SetMaterial(0, NewMaterial);
} See Also
Tags
Version History
Introduced in: 4.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?