RealDocs

ACharacter::FindComponentByClass

function Engine Since 4.0
#include "GameFramework/Character.h"
Access: public Specifiers: virtualoverride

Description

Returns the first component of the given class attached to this character. ACharacter overrides this to prioritize its private subobjects (Mesh, CharacterMovement, CapsuleComponent) before searching the generic component list.

Caveats & Gotchas

  • The override means UCharacterMovementComponent, UCapsuleComponent, and USkeletalMeshComponent are found via this path even though they are private — prefer the dedicated typed getters (GetCharacterMovement(), GetCapsuleComponent(), GetMesh()) which avoid the cast and the search.
  • The templated version FindComponentByClass<T>() delegates to the AActor base — it does NOT go through this override. Results are identical in practice but the code path differs.

Signature

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

Parameters

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

Return Type

UActorComponent*

Example

Find movement component by class C++
UCharacterMovementComponent* MoveComp = Cast<UCharacterMovementComponent>(
    FindComponentByClass(UCharacterMovementComponent::StaticClass()));
// Prefer: GetCharacterMovement() instead for ACharacter.

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.