Get All Actors Of Class C++

Help me write code in C ++, otherwise I don’t understand anything in programming.

    TSubclassOf<AEnemy> ClassToFind = AMyClass:GetClass();
    TArray<AActor*> FoundActors;
    UGameplayStatics::GetAllActorsOfClass(GetWorld(), ClassToFind, FoundActors);
1 Like

The description says

static void GetAllActorsOfClass
(
    const UObject * WorldContextObject,
    TSubclassOf< AActor > ActorClass,
    TArray< AActor * > & OutActors
)

You wrote

TSubclassOf<AEnemy>

What is AEnemy?

You’re right; I illustrated how you could specify classes that are more narrow than AActor assuming the class you want to look for comes from some configurable property. AEnemy would be a APawn subclass that you define for enemies you want to find.

You can totally just use AActor.

1 Like