Structs are fixed-shape data containers used to group related values, like a strongly typed table in Lua.
They help keep things organized and efficient in Unreal, and are commonly used for positions, colors, stats, and other reusable sets of data.
A generic, dynamic array container similar to std::vector in C++ or Lua tables, but with explicit control over capacity, type safety, and memory layout. Used to store a sequence of elements with built-in utility methods
Example
localMyArray=TArray("int")-- Creates a typed array of integers
Usage
-- Create a typed array of stringslocalitems=TArray("string")-- Add and AddUniqueitems:Add("Apple")items:Add("Banana")items:AddUnique("Banana")-- Won't be added again-- Insert at specific indexitems:Insert("Orange",1)-- Insert at index 1-- Find index of an itemlocalorangeIndex=items:Find("Orange")-- Remove by indexitems:Remove(orangeIndex)-- Remove by itemitems:RemoveItem("Banana")-- Get number of elementsprint("Length:",items:Length())print("Num:",items:Num())-- Alias for Length-- Get and Set itemslocalfirstItem=items:Get(0)items:Set(0,"Mango")-- GetRef returns a reference (for modifying structs)localref=items:GetRef(0)print("Ref to first item:",ref)-- Check if array contains somethingifitems:Contains("Mango")thenprint("We have Mango!")end-- Validity checkifitems:IsValidIndex(0)thenprint("Index 0 is valid.")end-- Swap elementsitems:Add("Pineapple")items:Swap(0,1)-- Shuffle the arrayitems:Shuffle()-- Get last valid indexlocallastIndex=items:LastIndex()print("Last Index:",lastIndex)-- Append another arraylocalextras=TArray("string")extras:Add("Grapes")extras:Add("Peach")items:Append(extras)-- Reserve space (useful for performance)items:Reserve(20)-- Resize array to fixed size (fills with nil)items:Resize(10)-- Get raw memory address (lightuserdata, unsafe)localaddr=items:GetData(0)print("Memory address of index 0:",addr)-- Convert to native Lua tablelocalnative=items:ToTable()fori,vinipairs(native)doprint("Native table item:",v)end-- Clear the arrayitems:Clear()print("Array cleared. Length:",items:Length())
A generic, unordered container for storing unique elements — similar to std::unordered_set in C++ or a Lua table used as a set. TSet ensures there are no duplicates and provides fast lookup and removal
Example
localMySet=TSet("string")-- Creates a typed set of strings
Usage
-- Create a typed set of integerslocalnumbers=TSet("int")-- Add elementsnumbers:Add(5)numbers:Add(10)numbers:Add(5)-- Duplicate, ignored-- Get size of the setprint("Length:",numbers:Length())print("Num:",numbers:Num())-- Alias for Length-- Check if set contains an itemifnumbers:Contains(10)thenprint("10 is in the set")end-- Remove an itemlocalremoved=numbers:Remove(5)print("Removed 5:",removed)-- true-- Remove non-existent itemlocalfailed=numbers:Remove(99)print("Removed 99:",failed)-- false-- Convert to TArraylocalasArray=numbers:ToArray()print("As TArray, length:",asArray:Length())-- Convert to Lua tablelocalluaTable=numbers:ToTable()for_,vinipairs(luaTable)doprint("Lua table item:",v)end-- Clear the setnumbers:Clear()print("Set cleared. Length:",numbers:Length())
A generic key-value container similar to std::unordered_map in C++ or a Lua table with indexed keys. It provides fast lookup, replacement, and key/value iteration with type safety
Example
localmap=TMap("string","int")-- Creates a map with string keys and integer values
Usage
-- Create a typed map with string keys and int valueslocalscores=TMap("string","int")-- Add key-value pairsscores:Add("Alice",1200)scores:Add("Bob",950)scores:Add("Charlie",1500)-- Overwrite an existing keyscores:Add("Alice",1300)-- Replaces old value-- Get number of entriesprint("Length:",scores:Length())print("Num:",scores:Num())-- Alias for Length-- Find valueslocalaliceScore=scores:Find("Alice")print("Alice's score:",aliceScore)-- FindRef returns reference (if applicable in your system)localref=scores:FindRef("Bob")print("Reference to Bob's score:",ref)-- Remove entrylocalremoved=scores:Remove("Charlie")print("Removed Charlie:",removed)-- true-- Remove non-existent keylocalfailed=scores:Remove("Eve")print("Removed Eve:",failed)-- false-- Get all keyslocalkeys=scores:Keys()fori=0,keys:Length()-1doprint("Key:",keys:Get(i))end-- Get all valueslocalvalues=scores:Values()fori=0,values:Length()-1doprint("Value:",values:Get(i))end-- Convert to Lua tablelocalluaTable=scores:ToTable()fork,vinpairs(luaTable)doprint("Lua table entry:",k,v)end-- Clear the mapscores:Clear()print("Map cleared. Length:",scores:Length())