GameplayStatics/GetActorOfClass

Find the first actor in the world with the specified class. Include #include "Kismet/GameplayStatics.h" Syntax AActor* GetActorOfClass(const UObject* WorldContextObject, TSubclassOf Actor...

Updated about 4 years ago Edit Page Revisions

Find the first actor in the world with the specified class.

Include

#include "Kismet/GameplayStatics.h"

Syntax

AActor* GetActorOfClass(const UObject* WorldContextObject, TSubclassOf ActorClass)

Parameters

WorldContextObject

Any UObject that exists in the world.

ActorClass

The class of actor which you want to find.

Examples

Real world use cases:

Example 1

TODO: Add more details

// Defined types
TSubclassOf SomeActorClass;
AActor* FoundActor;
...
FoundActor = GetActorOfClass(GetWorld(), SomeActorClass);
if (FoundActor)
{
    // Use the found actor
}