Unreal Engine 5 · Blueprint → C++
Get Actor Of Class in Unreal Engine 5 C++
Get Actor Of Class maps to UGameplayStatics::GetActorOfClass, which returns the first actor in the level matching 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"
// First found actor
AActor* Actor;
if (ActorClass)
{
Actor = UGameplayStatics::GetActorOfClass(
this, // World context object
ActorClass // Actor class
);
}Set up the class reference
Declare TSubclassOf<AActor> ActorClass as a UPROPERTY(EditAnywhere) so the target class can be picked in the editor. Using TSubclassOf instead of a raw pointer gives you a type-safe class picker in the details panel.
The C++ equivalent
Include Kismet/GameplayStatics.h and call UGameplayStatics::GetActorOfClass(this, ActorClass). It returns the first matching AActor* it finds, or null if none exists. Guard the call with an if (ActorClass) check so you never query with an unset class.
When to use it
This is convenient when you expect exactly one instance of a class in the level, such as a single game-mode helper or a unique manager actor. It iterates the level internally, so avoid calling it every frame; cache the result instead. To retrieve every match, use GetAllActorsOfClass.
Frequently asked questions
How do I find an actor by class in UE5 C++?+
Call UGameplayStatics::GetActorOfClass(this, ActorClass) with a TSubclassOf<AActor>. It returns the first matching actor or null.
Is GetActorOfClass expensive?+
It scans the level's actors, so it should not be called every tick. Cache the returned pointer once and reuse it instead of querying repeatedly.