RealDocs

AActor::FindComponentByInterface

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 implements the specified UInterface. The templated overload `FindComponentByInterface<IMyInterface>()` returns the correctly typed interface pointer and is preferred in C++.

Caveats & Gotchas

  • The non-template overload returns a raw `UActorComponent*`. You must Cast<> to the interface type yourself, and Cast to a UInterface subtype is unusual — use the template overload instead.
  • In UE 5.5 the old template overload (`template<class T UE_REQUIRES(TPointerIsConvertibleFromTo<T, UInterface>::Value)>`) was deprecated because it incorrectly cast to the UInterface reflection type rather than the IInterface type. Use `FindComponentByInterface<IMyInterface>()` with the `I`-prefixed interface.
  • Like FindComponentByClass, this does not recurse into ChildActorComponent hierarchies.

Signature

virtual UActorComponent* FindComponentByInterface(const TSubclassOf<UInterface> Interface) const

Parameters

Name Type Description Default
Interface const TSubclassOf<UInterface> The UInterface-derived class to search for.

Return Type

UActorComponent*

Example

Find a component by interface (C++ preferred form, UE 5.5+) C++
// Correct: pass the I-prefixed interface type
IMyWeaponInterface* WeaponComp = MyActor->FindComponentByInterface<IMyWeaponInterface>();
if (WeaponComp)
{
    WeaponComp->Fire();
}

Version History

Introduced in: 4.0

Version Status Notes
5.6 stable
5.5 stable Old template overload (UInterface-typed) deprecated; new IInterface-typed template overload added.

Feedback

Was this helpful?

Suggest an edit

Select a field above to begin editing.