Is there a way to make GetAllActorsOfClass return an array of a class instead of AActors?

Yep, that’s how it works. The blueprint version returns an array of your class, even though I can’t see any casting in the GetAllActorsOfClass() implementation.

I just cast them all manually to the class I need:

TArray<AMyClass*> MyActors;
TArray<AActor*> OutActors;

UGameplayStatics::GetAllActorsOfClass(GetWorld(), AMyClass::StaticClass(), OutActors);
for (AActor* a : OutActors)
{
    MyActors.Add(Cast<AMyClass>(a));
}

and then just use this MyActors array.

1 Like