GameplayStatics/GetActorArrayAverageLocation
Find the average FVector location of an array of actors. Include #include "Kismet/GameplayStatics.h" Syntax static FVector GetActorArrayAverageLocation(const TArray& Actors) Examples ...
Find the average FVector location of an array of actors.
Include
#include "Kismet/GameplayStatics.h"
Syntax
static FVector GetActorArrayAverageLocation(const TArray& Actors)
Examples
Real world use cases:
Example 1
Perhaps you have a couch coop game, and want to position your spectator camera actor in the middle of all your players.
// Types
FVector CameraPositionVector;
TArray Players;
...
// Done only once at beginning of level (Expensive operation)
UGameplayStatics::GetAllActorsOfClass(this, AMyPlayerCharacter::StaticClass(), Players);
...
// Done frequently (perhaps in tick)
CameraPositionVector = GetActorArrayAverageLocation(Players)
...
// Done as frequently as the position as changed.
SomeSpectatorCameraActor->SetActorLocation(CameraPosition);