RealDocs

AActor::GetComponentsByInterface

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

Description

Returns all components on this actor that implement the specified UInterface. Useful for decoupled system design where you interact with components via interfaces rather than concrete types.

Caveats & Gotchas

  • Only finds components that implement the interface via C++ inheritance (class UMyComp : public UActorComponent, public IMyInterface) or Blueprint interface implementation. Components that do not declare the interface will not be returned even if they have matching functions.
  • Returns UActorComponent* base pointers — call IMyInterface::Execute_MyFunction(Comp, ...) or Cast<IMyInterface>(Comp) to invoke interface methods safely.
  • Also consider the related FindComponentByInterface() if you only need the first match, which avoids constructing the array.

Signature

ENGINE_API TArray<UActorComponent*> GetComponentsByInterface(TSubclassOf<UInterface> Interface) const

Parameters

Name Type Description Default
Interface TSubclassOf<UInterface> The interface class that returned components must implement.

Return Type

TArray<UActorComponent*>

Example

Call an interface method on all matching components C++
TArray<UActorComponent*> Interactables = GetComponentsByInterface(UInteractableInterface::StaticClass());
for (UActorComponent* Comp : Interactables)
{
	IInteractableInterface::Execute_OnInteract(Comp, this);
}

Version History

Introduced in: 4.17

Version Status Notes
5.6 stable

Feedback

Was this helpful?

Suggest an edit

Select a field above to begin editing.