AActor::FindComponentByTag
#include "GameFramework/Actor.h"
Access: public
Specifiers: UFUNCTIONBlueprintCallable
Description
Searches the actor's component list and returns the first component that is of type ComponentClass and has the specified tag. Returns nullptr if no match is found.
Caveats & Gotchas
- • Searches component tags (set via ComponentTags array in the component), not actor tags. Component tags and actor tags are separate systems.
- • Returns only the first match — if multiple components share the same tag and class, use GetComponentsByTag() to retrieve all of them.
- • There is a templated C++ overload FindComponentByTag<T>(Tag) that avoids the cast: T* FindComponentByTag(const FName& Tag) const.
Signature
ENGINE_API UActorComponent* FindComponentByTag(TSubclassOf<UActorComponent> ComponentClass, FName Tag) const Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| ComponentClass | TSubclassOf<UActorComponent> | The component class to filter by. | — |
| Tag | FName | The component tag to search for. | — |
Return Type
UActorComponent* Example
Find a tagged mesh component C++
// Find the first UStaticMeshComponent with tag "WeaponMesh"
if (UActorComponent* Found = FindComponentByTag(UStaticMeshComponent::StaticClass(), FName("WeaponMesh")))
{
UStaticMeshComponent* Mesh = Cast<UStaticMeshComponent>(Found);
Mesh->SetVisibility(true);
}
// Or use the templated helper:
if (UStaticMeshComponent* Mesh = FindComponentByTag<UStaticMeshComponent>(FName("WeaponMesh")))
{
Mesh->SetVisibility(true);
} Tags
Version History
Introduced in: 4.17
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?