Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

TArray

TArray is Unreal Engine’s array implementation.
The interface described below differs in several ways.

The first and most important difference is that it’s 1-indexed to match a Lua programmers expectation of a table-like structure.

The second difference is that it’s backed by FScriptArray instead of TArray<T> because Lua doesn’t have a template system.
The subtype T is resolved automatically at runtime whenever necessary.

Inheritance

RemoteObject

Metamethods

__index

  • Usage: TArray[ArrayIndex]
  • Return type: auto
  • Attempts to retrieve the value at the specified integer offset ArrayIndex in the array.
  • Can return any type, you can use the type() function on the returned value to figure out what Lua class it’s using (if non-trivial type).

__newindex

  • Usage: TArray[ArrayIndex] = NewValue
  • Attempts to set the value at the specified integer offset ArrayIndex in the array to NewValue.

__len

  • Usage: #TArray
  • Return type: integer
  • Returns the number of current elements in the array.

Methods

GetArrayAddress()

  • Return type: integer
  • Returns: the address in memory where the TArray struct is located.

GetArrayNum()

  • Return type: integer
  • Returns: the number of current elements in the array.

GetArrayMax()

  • Return type: integer
  • Returns: the maximum number of elements allowed in this array (aka capacity).

GetArrayDataAddress()

  • Return type: integer
  • Returns: the address in memory where the data for this array is stored.

Empty()

  • Clears the array.

ForEach(function Callback)

  • Iterates the entire TArray and calls the callback function for each element in the array.
  • The callback params are: integer index, RemoteUnrealParam elem | LocalUnrealParam elem.
  • Use elem:get() and elem:set() to access/mutate an array element.
  • The callback can optionally return true to break out of the loop early.