RealDocs

UKismetMathLibrary::MinOfIntArray

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

Description

Finds the minimum integer in an array and its index. Returns MinValue=0 and IndexOfMinValue=-1 on an empty array.

Caveats & Gotchas

  • An empty array returns MinValue of 0 (not INT_MAX) and an index of -1 — verify the index before using MinValue to avoid treating the sentinel as a real result.
  • When duplicates share the minimum value, only the first occurrence index is returned.

Signature

static ENGINE_API void MinOfIntArray(const TArray<int32>& IntArray, int32& IndexOfMinValue, int32& MinValue);

Parameters

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

Return Type

void

Example

Find lowest health target C++
TArray<int32> HealthValues = { 80, 15, 95, 15, 60 };
int32 Index, MinHealth;
UKismetMathLibrary::MinOfIntArray(HealthValues, Index, MinHealth);
// MinHealth == 15, 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.