I’m attempting to use UGameplayStatistics::GetAllActorsOfClass, which seems to accept only a TArray<AActor*>. I think there’s two ways to do this, but I’m not sure how to go about either one.
1.) If I can make GetAllActorsOfClass() output to a TArray<ACharacter*>, then I can use that.
2.) If not the former, I can do something that takes characters from TArray<AActor*> and puts them into a TArray<ACharacter*>
Here’s what I have so far:
TArray<ACharacter*> UServerCharacterRegistry::GetAllCharactersInWorld()
{
TSubclassOf<ACharacter> ActorClass = ACharacter::StaticClass();
TArray<AActor*> FoundActors;
UGameplayStatics::GetAllActorsOfClass(GetWorld(), ActorClass, FoundActors);
TArray<ACharacter*> OutCharacters;
for (AActor* index : FoundActors)
{
//If AActor is ACharacter, Add to OutCharacters;
}
return OutCharacters;
}
If someone could point me in the right direction or tell me how to go about this, I’d appreciate it. I’ve been stuck on this for a couple days now.
I’ve never used “Cast<class>” before, but it certainly seems handy so I’ll be looking that up. Thank you very much Helghast, I appreciate it! (And thanks for showing how I could reduce the line count too )
Since GetAllActorsOfClass is rather expensive to call you could take advantage of the existing Pawn iterator and filter out the Characters in that. Here I used the Blueprint Function Library class to make it easy to get from anywhere.