RealDocs

AActor::FindComponentByInterface (IInterface template overload)

function Engine Since 5.5
#include "GameFramework/Actor.h"
Access: public Specifiers: const

Description

The `TIsIInterface`-constrained template overload of `FindComponentByInterface`, introduced in UE 5.5 to replace the deprecated UInterface-typed version. Pass the `I`-prefixed interface type (e.g. `IMyInterface`) and receive a correctly typed pointer with no manual cast required.

Caveats & Gotchas

  • `UE_REQUIRES` is an Unreal macro that expands to a C++20 `requires` clause (or a SFINAE enable_if on older standards). The constraint `TIsIInterface<T>::Value` ensures T is a proper IInterface type, preventing accidental use with U-prefixed reflection classes.
  • Because `TIsIInterface` matches only the I-prefixed interface class, passing the U-prefixed class (e.g. UMyInterface) will trigger a compile error, which is the intended behavior — always use the I prefix.
  • The old overload constrained by `TPointerIsConvertibleFromTo<T, UInterface>::Value` is still present but marked UE_DEPRECATED(5.5) and will be removed in a future version.

Signature

template<class T UE_REQUIRES(TIsIInterface<T>::Value)> T* FindComponentByInterface() const

Return Type

T*

Example

Correct usage with I-prefixed interface type C++
// UE 5.5+: use I-prefixed type; UE_REQUIRES ensures correct constraint at compile time
IInteractable* Interactable = SomeActor->FindComponentByInterface<IInteractable>();
if (Interactable)
{
    Interactable->Interact(PlayerPawn);
}

Version History

Introduced in: 5.5

Version Status Notes
5.6 stable
5.5 stable Introduced as replacement for the deprecated UInterface-typed template overload.

Feedback

Was this helpful?

Suggest an edit

Select a field above to begin editing.