Update: I added a tutorial on answer and code for your question to my main C++ thread
http://forums.epicgames.com/threads/972861-TUTORIALS-C-for-UE4-gt-gt-New-Complete-Code-Custom-Screenshot-Save-System-For-You?p=31679652&posted=1#post31679652
Dear Kasuhisa,
Hi there!
I do think I have the answers for you
The function I think you want is:
line 602 of Actor.h
/** See if this actor contains the supplied tag */
UFUNCTION(BlueprintCallable, Category="Misc")
bool HasTag(FName Tag) const;
To loop through ALL actors, you can check out my tutorial on looping through all actors, here’s the code
http://forums.epicgames.com/threads/972861-Tutorials-C-for-UE4-Code-Samples-gt-gt-New-Video-Freeze-Render-When-Tabbed-Out?p=31663817&viewfull=1#post31663817
void AYourControllerClass::PrintAllActorsLocations()
{
//EngineUtils.h
FActorIterator AllActorsItr = FActorIterator(GetWorld());
//While not reached end (overloaded bool operator)
while (AllActorsItr)
{
ClientMessage(AllActorsItr->GetClass()->GetDesc());
ClientMessage(AllActorsItr->GetActorLocation().ToString());
//next actor
++AllActorsItr;
}
}
To loop through a subset of all actors based on a class of your choosing, for example, you only want to search through all Static Mesh Actors and look for a certain tag:
http://forums.epicgames.com/threads/972861-TUTORIALS-C-for-UE4-gt-gt-New-Change-Global-Post-Process-During-Game!?p=31667115&viewfull=1#post31667115
void AYourController::PrintAllSMAActorsLocations()
{
//EngineUtils.h
TActorIterator< AStaticMeshActor > ActorItr =
TActorIterator< AStaticMeshActor >(GetWorld());
//While not reached end (overloaded bool operator)
while (ActorItr)
{
ClientMessage(ActorItr->GetClass()->GetDesc());
ClientMessage(ActorItr->GetActorLocation().ToString());
//next actor
++ActorItr;
}
}
So here’s a full code example using actor has tag to check if any Static Mesh Actors in the level have a certain tag:
void AYourController::AddSMAActorsWithTag(const FName &TheSearchTag, TArray &SMAsWithTag)
{
//SMAsWithTag.Empty(); //uncomment this line to replace a previous search
//EngineUtils.h
TActorIterator< AStaticMeshActor > ActorItr =
TActorIterator< AStaticMeshActor >(GetWorld());
//While not reached end (overloaded bool operator)
while (ActorItr)
{
//debug info, useful if this function is in a player controller class
//ClientMessage(ActorItr->GetClass()->GetDesc());
//ClientMessage(ActorItr->GetActorLocation().ToString());
if(ActorItr->HasTag(TheSearchTag))
{
SMAsWithTag.AddItem(Cast(*ActorItr));
}
//next actor
++ActorItr;
}
}
//you should pass in an empty TArray for the function to fill, ex:
TArray MySMAs; //could be global class var or declared in a function;