[c++] Get Components By Tag Syntax

Can someone help me with the GetComponentsByTag to get an array of the components of a BP? I’ve looked everywhere and cant find a good example.

I have my class, C_GridTile thats the parent of BP_GridTile.
In BP_GridTile there is a staticmesh component that is the child of a scene component that is the root, i want a reference to that static mesh component in c++ construct.

I have this:
TArray < UStaticMeshComponent* > arrayExample (TSubclassOf AC_GridTile, FName ComponentTag);

But i get error when compiling
C:\Users\name\Desktop\AStarProject\AIPathfinding\Source\AIPathfinding\Private\C_GridTile.cpp(79) : error C4930: ‘TArray arrayExample(TSubclassOf,FName)’: prototyped function not called (was a variable definition intended?)

Can someone tell how i should do the syntax so afterwards i have an array of the components with that tag?

Thanks

Maybe someone else needs this.
Your syntax should look like this:

const AActor * parent = GetOwner();

TArray MyArrowComponentArray2 = parent->GetComponentsByTag(UArrowComponent::StaticClass(), FName(“Arrow”));
for (UActorComponent * it : MyArrowComponentArray2)

{

Name = it->GetName();

UE_LOG(LogTemp, Warning, TEXT(“ARROW Name : %s”), *Name);

}

1 Like