RealDocs

UKismetMathLibrary::AverageOfIntArray

function Engine Blueprint Since 4.20
#include "Kismet/KismetMathLibrary.h"
Access: public Specifiers: staticBlueprintPureUFUNCTION

Description

Computes the arithmetic mean of an integer array as a float. Returns 0 for an empty array.

Caveats & Gotchas

  • The sum is accumulated as a float before dividing, which can lose precision for very large integer values (> ~16 million) where float32 cannot represent all int32 values exactly.
  • An empty array produces AverageValue of 0.0f with no error or indication — always check array length if 0 is a meaningful value in your domain.

Signature

static ENGINE_API void AverageOfIntArray(const TArray<int32>& IntArray, float& AverageValue);

Parameters

Name Type Description Default
IntArray const TArray<int32>& The array to average.
AverageValue float& Output: the arithmetic mean of the array elements.

Return Type

void

Example

Average damage dealt in a round C++
TArray<int32> DamageDealt = { 120, 85, 200, 60 };
float Avg;
UKismetMathLibrary::AverageOfIntArray(DamageDealt, Avg);
// Avg == 116.25f

Version History

Introduced in: 4.20

Version Status Notes
5.6 stable

Feedback

Was this helpful?

Suggest an edit

Select a field above to begin editing.