RealDocs

UKismetMathLibrary::MaxOfFloatArray

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

Description

Finds the maximum float in an array and its index. Returns MaxValue=0 and IndexOfMaxValue=-1 on an empty array.

Caveats & Gotchas

  • NaN values in the array can cause unpredictable behavior since float comparisons involving NaN always return false — sanitize inputs if NaN may be present.
  • An empty array yields MaxValue of 0 (not -FLT_MAX) — check IndexOfMaxValue != -1 before trusting MaxValue.

Signature

static ENGINE_API void MaxOfFloatArray(const TArray<float>& FloatArray, int32& IndexOfMaxValue, float& MaxValue);

Parameters

Name Type Description Default
FloatArray const TArray<float>& The array to search.
IndexOfMaxValue int32& Output: index of the maximum value. -1 if array is empty.
MaxValue float& Output: the maximum value found. 0 if array is empty.

Return Type

void

Example

Find highest weight in a weighted list C++
TArray<float> Weights = { 0.3f, 0.8f, 0.1f, 0.5f };
int32 Index;
float MaxWeight;
UKismetMathLibrary::MaxOfFloatArray(Weights, Index, MaxWeight);
// MaxWeight == 0.8f, Index == 1

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.