I have a PlayerControl.cpp
class which derives from Pawn class
In that class , I have a method to get all Actors in Map
TSubclassOf<AEnemy> ClassToFind;
TArray<AActor*> FoundEnemies;
UGameplayStatics::GetAllActorsOfClass(GetWorld(), ClassToFind, FoundEnemies);
But FoundEnemies array is always empty , When I do the same thing in BP it works.
Can someone tell me why is this not working in C++ ? Or If I am doing wrong , How to do it correct ?
Finally , I found answer for my own question
I should assign a value to the variable "ClassToFind"
So adding line classToFind = AEnemy::StaticClass();
fixed the issue
TSubclassOf<AEnemy> classToFind;
classToFind = AEnemy::StaticClass();
TArray<AActor*> foundEnemies;
UGameplayStatics::GetAllActorsOfClass(GetWorld(), classToFind, foundEnemies);