Why GetAllActorsOfClass returns empty?

Kas

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 ?

Kas

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);

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Why querying google cloud files returns an empty list?

Why a function checking if a string is empty always returns true?

Why preg_match returns some empty elements?

Why json_encode returns empty brackets?

why require("angular") returns an empty object

Why every? function returns true with empty vector in Clojure?

Why POST Request from POSTMAN returns empty?

while adding empty array and object, why console returns like this?

Why hasChildNodes returns true for an Empty Node?

Why does MongoDB $size returns 1 for an empty sub-array?

Google Cloud Function - Why bucket always returns empty array of files?

Why Python BeautifulSoup returns a empty list?

Why null statement ToString() returns an empty string?

Why my getElementsByTagName returns an empty NodeList?

why Object.keys(Array.prototype) returns empty array?

Why does this range query returns empty results?

Why returning values from sqlite returns an empty array

Why Laravel View::make returns empty string without error?

Why query returns empty collection?

Why is this function returns an empty array?

Explain why encode method returns empty Vector

why SQL inner join returns empty result in laravel?

Why do typescript adds empty string to the union of conditional returns?

Why does Marshmallow return empty for multiple items but returns a single item?

Why Laravel query returns empty array?

Why is this async function returning empty on the first try, but then it returns everything?

Why passing function object to Object.keys() returns empty array?

Why joining two tables onto parent table returns empty query

Why empty stylesheet returns text from XML?