Unreal Engine 5 · Blueprint → C++
Get All Actors Of Class in Unreal Engine 5 C++
Get All Actors Of Class maps to UGameplayStatics::GetAllActorsOfClass, which fills a TArray<AActor*> with every actor of a given TSubclassOf<AActor>.
Blueprint node & C++ equivalent

private:
// The class needs to be set in blueprint
UPROPERTY(EditAnywhere, meta = (AllowPrivateAccess = "true"))
TSubclassOf<AActor> ActorClass;#include "Kismet/GameplayStatics.h"
// Result will be stored here
TArray<AActor*> Actors;
if (ActorClass)
{
UGameplayStatics::GetAllActorsOfClass(
this, // World context object
ActorClass, // Actor class
Actors // (Output) Result
);
}The C++ equivalent
Include Kismet/GameplayStatics.h and call UGameplayStatics::GetAllActorsOfClass(this, ActorClass, Actors). The first argument is a world context object, the second is the TSubclassOf<AActor> to match, and the third is an out TArray<AActor*> that receives the results.
How to use it in C++
Declare the output array, TArray<AActor*> Actors, before the call, and wrap it in if (ActorClass) to avoid querying with an unset class. After the call, iterate the array to operate on each actor. The array is cleared and refilled on every call.
Performance note
This function iterates over all actors in the world, so calling it every frame is wasteful. Build or cache the list once when actors are spawned or when the level loads. For a single instance, prefer GetActorOfClass.
Frequently asked questions
How do I get all actors of a class in UE5 C++?+
Call UGameplayStatics::GetAllActorsOfClass(this, ActorClass, Actors) with a TSubclassOf<AActor> and a TArray<AActor*> output parameter.
Why is GetAllActorsOfClass slow when called often?+
It loops over every actor in the level on each call. Cache the result instead of running it each tick to avoid the per-frame cost.