RealDocs

UGameplayStatics::GetActorOfClass

function Engine Blueprint Since unknown
#include "Kismet/GameplayStatics.h"
Access: public Specifiers: static

Description

Returns the first actor of the given class found in the world, or null if none exists. Iteration order is not guaranteed.

Signature

static ENGINE_API AActor* GetActorOfClass(const UObject* WorldContextObject, TSubclassOf<AActor> ActorClass)

Parameters

Name Type Description Default
WorldContextObject const UObject* Any valid UObject in the world.
ActorClass TSubclassOf<AActor> The class to find. Returns the first match found.

Return Type

AActor*

Caveats & Gotchas

  • Still iterates the full actor list to find the first match — not O(1). Avoid in Tick.
  • The returned actor is the first one encountered during iteration, which is implementation-defined. Do not rely on a consistent result if multiple instances exist.
  • Returns null if no actor of that class exists. Always IsValid() check.

Example

Find the game state or a singleton actor C++
AMyGameState* GS = Cast<AMyGameState>(
	UGameplayStatics::GetActorOfClass(this, AMyGameState::StaticClass())
);
if (IsValid(GS))
{
	GS->NotifyRoundStart();
}

Version History

Introduced in: unknown

Version Status Notes
5.6 stable

Feedback

Was this helpful?

Suggest an edit

Select a field above to begin editing.