RealDocs

UGameplayStatics::GetActorArrayAverageLocation

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

Description

Returns the arithmetic mean (centroid) of the world locations of all actors in the array. Useful for finding the centre of a group of actors.

Caveats & Gotchas

  • Returns FVector::ZeroVector when the input array is empty — always guard against this if the array might be empty to avoid treating the world origin as a valid centroid.
  • Uses each actor's GetActorLocation(), which is the pivot/root component origin, not a visual or bounding-box centre. Actors with off-centre pivots will skew the result.

Signature

static ENGINE_API FVector GetActorArrayAverageLocation(const TArray<AActor*>& Actors);

Parameters

Name Type Description Default
Actors const TArray<AActor*>& Array of actors whose locations are averaged.

Return Type

FVector

Example

Find the centre of a group of enemies C++
TArray<AActor*> Enemies;
UGameplayStatics::GetAllActorsOfClass(this, AEnemyCharacter::StaticClass(), Enemies);
if (Enemies.Num() > 0)
{
    FVector Centroid = UGameplayStatics::GetActorArrayAverageLocation(Enemies);
    DrawDebugSphere(GetWorld(), Centroid, 50.f, 12, FColor::Red, false, 2.f);
}

Version History

Introduced in: 4.0

Version Status Notes
5.6 stable

Feedback

Was this helpful?

Suggest an edit

Select a field above to begin editing.