RealDocs

UKismetArrayLibrary::Array_Swap

function Engine Blueprint Since unknown
#include "Kismet/KismetArrayLibrary.h"
Access: public Specifiers: staticBlueprintCallableCustomThunk

Description

Swaps the elements at two indices in an array.

Caveats & Gotchas

  • If FirstIndex and SecondIndex are equal, the call is a safe no-op.
  • Out-of-range indices log a warning and leave the array unchanged rather than crashing.
  • Displayed in Blueprint as 'Swap Array Elements' with CompactNodeTitle 'SWAP'.

Signature

static void Array_Swap(UPARAM(ref) TArray<int32>& TargetArray, int32 FirstIndex, int32 SecondIndex);

Parameters

Name Type Description Default
TargetArray UPARAM(ref) TArray<int32>& The array to perform the swap in. Passed by reference and mutated in place.
FirstIndex int32 The index of one element to swap.
SecondIndex int32 The index of the other element to swap.

Return Type

void

Example

Swap two elements C++
TArray<int32> Values = { 1, 2, 3 };
UKismetArrayLibrary::Array_Swap(Values, 0, 2);
// Values is now { 3, 2, 1 }

Version History

Introduced in: unknown

Version Status Notes
5.6 stable

Feedback

Was this helpful?

Suggest an edit

Select a field above to begin editing.