RealDocs

UGameplayStatics::GetAllActorsOfClass

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

Description

Fills OutActors with all actors of the given class currently in the world. Performs a full world actor iteration — avoid calling every frame.

Signature

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

Parameters

Name Type Description Default
WorldContextObject const UObject* Any valid UObject in the world.
ActorClass TSubclassOf<AActor> The class to search for. Includes all subclasses.
OutActors TArray<AActor*>& Output array populated with all matching actors.

Return Type

void

Caveats & Gotchas

  • Iterates the entire actor list — O(n) where n is the total actor count in the level. Calling this in Tick will cause severe performance problems on complex levels.
  • OutActors is not cleared before population — call OutActors.Reset() first if reusing the array across calls.
  • Includes actors that are hidden, pending kill, or not yet fully initialized. Filter with IsValid() and any additional state checks.
  • For runtime actor tracking, maintain your own TArray and use OnActorSpawned/OnDestroyed delegates instead of polling with this function.

Example

One-time gather of all enemies at level start C++
void AMyGameMode::BeginPlay()
{
	Super::BeginPlay();

	TArray<AActor*> Found;
	UGameplayStatics::GetAllActorsOfClass(this, AEnemy::StaticClass(), Found);

	for (AActor* Actor : Found)
	{
		if (AEnemy* Enemy = Cast<AEnemy>(Actor))
		{
			RegisterEnemy(Enemy);
		}
	}
}

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.