Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why GetAllActorsOfClass returns empty?

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 ?

like image 389
Kas Avatar asked Sep 09 '16 07:09

Kas


1 Answers

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);
like image 57
Kas Avatar answered Sep 30 '22 04:09

Kas