UKismetMathLibrary::GetVectorArrayAverage
#include "Kismet/KismetMathLibrary.h"
Access: public
Specifiers: staticUFUNCTIONBlueprintPure
Description
Computes the arithmetic mean of an array of vectors by averaging each component independently.
Caveats & Gotchas
- • Returns (0,0,0) if the input array is empty — the caller must guard against this if an empty array would be semantically incorrect (e.g., averaging bone positions when a skeleton has no bones).
- • This is a plain centroid calculation, not a weighted average. All vectors contribute equally. For direction averaging, averaging unit vectors and re-normalizing is only valid when the vectors are spread within a hemisphere; averaging diametrically opposed unit vectors yields a zero vector.
Signature
static ENGINE_API FVector GetVectorArrayAverage(const TArray<FVector>& Vectors); Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| Vectors | const TArray<FVector>& | Array of vectors to average. | — |
Return Type
FVector Example
Find the centroid of a set of actor positions C++
TArray<FVector> Positions;
for (AActor* Actor : TargetActors)
{
Positions.Add(Actor->GetActorLocation());
}
FVector Centroid = UKismetMathLibrary::GetVectorArrayAverage(Positions); Version History
Introduced in: 4.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?