RealDocs

AActor::FindComponentByClass

function Engine Since 4.0
#include "GameFramework/Actor.h"
Access: public Specifiers: virtualconst

Description

Searches the actor's owned components and returns the first one that is an instance of the given class. The templated overload `FindComponentByClass<T>()` handles the cast automatically and is preferred in C++.

Caveats & Gotchas

  • Only returns the first matching component — if an actor has multiple components of the same type (e.g. two UStaticMeshComponents) and you need a specific one, use FindComponentByTag or iterate with GetComponents instead.
  • Does not search inside ChildActorComponents by default. Components belonging to a nested child actor are not owned by this actor and will not be found.
  • The Blueprint-callable equivalent is `GetComponentByClass`. `K2_GetComponentsByClass` returns all matches as an array and is preferred in Blueprint when multiple results are possible.

Signature

virtual UActorComponent* FindComponentByClass(const TSubclassOf<UActorComponent> ComponentClass) const

Parameters

Name Type Description Default
ComponentClass const TSubclassOf<UActorComponent> The class (or subclass) to search for.

Return Type

UActorComponent*

Example

Templated overload (preferred in C++) C++
UStaticMeshComponent* Mesh = MyActor->FindComponentByClass<UStaticMeshComponent>();
if (Mesh)
{
    Mesh->SetMaterial(0, NewMaterial);
}

Version History

Introduced in: 4.0

Version Status Notes
5.6 stable

Feedback

Was this helpful?

Suggest an edit

Select a field above to begin editing.