RealDocs

UKismetMathLibrary::MaxOfIntArray

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

Description

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

Caveats & Gotchas

  • An empty array returns MaxValue of 0 (not INT_MIN) and an index of -1 — always check the index before treating MaxValue as meaningful.
  • If multiple elements share the maximum value, IndexOfMaxValue points to the first occurrence only.

Signature

static ENGINE_API void MaxOfIntArray(const TArray<int32>& IntArray, int32& IndexOfMaxValue, int32& MaxValue);

Parameters

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

Return Type

void

Example

Find highest score C++
TArray<int32> Scores = { 10, 42, 7, 42, 3 };
int32 Index, MaxScore;
UKismetMathLibrary::MaxOfIntArray(Scores, Index, MaxScore);
// MaxScore == 42, 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.