Unreal Directive Docs
PluginsUDCoreFeaturesFunction Library

Array Functions

Array navigation and manipulation utilities

The UUDCoreArrayFunctionLibrary provides utilities for array navigation and manipulation, with support for looping behavior.

Index Navigation

Array_NextIndex

Returns the next index in an array, with optional looping.

When the current index is the last element:

  • If bLoop is true, returns 0 (wraps to beginning)
  • If bLoop is false, returns the last valid index

Array_NextIndex

TArray<int32> MyArray = { 0, 1, 2, 3 };
int32 CurrentIndex = 2;
bool bLoop = true;

int32 NextIndex = UUDCoreArrayFunctionLibrary::Array_NextIndex(MyArray, CurrentIndex, bLoop);
// Result: 3

// At the last element with looping:
CurrentIndex = 3;
NextIndex = UUDCoreArrayFunctionLibrary::Array_NextIndex(MyArray, CurrentIndex, bLoop);
// Result: 0 (loops back)

Parameters

NameTypeDescription
TargetArrayTArray<T>The array to navigate
Indexint32The current index
bLoopboolIf true, wrap to beginning when at end

Returns

NameTypeDescription
ReturnValueint32The next index

Array_PreviousIndex

Returns the previous index in an array, with optional looping.

When the current index is 0:

  • If bLoop is true, returns the last valid index (wraps to end)
  • If bLoop is false, returns 0

Array_PreviousIndex

TArray<int32> MyArray = { 0, 1, 2, 3 };
int32 CurrentIndex = 1;
bool bLoop = true;

int32 PrevIndex = UUDCoreArrayFunctionLibrary::Array_PreviousIndex(MyArray, CurrentIndex, bLoop);
// Result: 0

// At the first element with looping:
CurrentIndex = 0;
PrevIndex = UUDCoreArrayFunctionLibrary::Array_PreviousIndex(MyArray, CurrentIndex, bLoop);
// Result: 3 (loops to end)

Parameters

NameTypeDescription
TargetArrayTArray<T>The array to navigate
Indexint32The current index
bLoopboolIf true, wrap to end when at beginning

Returns

NameTypeDescription
ReturnValueint32The previous index

Use Cases

Cycling Through Menu Options

// Player presses "Next"
CurrentSelection = UUDCoreArrayFunctionLibrary::Array_NextIndex(MenuOptions, CurrentSelection, true);

// Player presses "Previous"
CurrentSelection = UUDCoreArrayFunctionLibrary::Array_PreviousIndex(MenuOptions, CurrentSelection, true);

Playlist Navigation

// Next track (loop when at end)
CurrentTrack = UUDCoreArrayFunctionLibrary::Array_NextIndex(Playlist, CurrentTrack, true);

// Previous track (loop when at beginning)
CurrentTrack = UUDCoreArrayFunctionLibrary::Array_PreviousIndex(Playlist, CurrentTrack, true);

Non-Looping Selection

// Navigate without looping (useful for lists with a clear beginning/end)
CurrentIndex = UUDCoreArrayFunctionLibrary::Array_NextIndex(Items, CurrentIndex, false);
// At the last element, this returns the last index instead of looping

These functions work with any array type in Blueprints and are templated in C++ for type safety.

Summary

FunctionDescription
Array_NextIndexGet the next index with optional looping
Array_PreviousIndexGet the previous index with optional looping

On this page