RealDocs

AActor::GetComponentByClass

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

Description

Returns the first component of the given class attached to this actor, or null if none is found. In C++ prefer the templated overload `GetComponentByClass<T>()` to avoid the cast.

Signature

UActorComponent* GetComponentByClass(TSubclassOf<UActorComponent> ComponentClass) const

Parameters

Name Type Description Default
ComponentClass TSubclassOf<UActorComponent> The class of component to search for.

Return Type

UActorComponent*

Caveats & Gotchas

  • Returns only the *first* matching component. If an actor has multiple components of the same type (e.g. two UStaticMeshComponents), use GetComponentsByClass instead.
  • In C++, the Blueprint-callable version returns UActorComponent* and requires a cast. The template version `GetComponentByClass<T>()` does the cast internally and is preferred.
  • The underlying implementation is FindComponentByClass — both do the same linear scan through the component array.

Example

Get a specific component in C++ C++
UStaticMeshComponent* Mesh = GetComponentByClass<UStaticMeshComponent>();
if (Mesh)
{
    Mesh->SetVisibility(false);
}

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.