RealDocs

TArray

class Core Blueprint Since 1.0
#include "Containers/Array.h"
Access: public

Description

The primary dynamic array container in Unreal Engine, equivalent to `std::vector`. Stores elements contiguously in memory. Supports UPROPERTY reflection for Blueprint integration and engine serialization. Provides ordered, random-access storage with amortized O(1) append.

Signature

template <typename InElementType, typename InAllocatorType = FDefaultAllocator> class TArray

Caveats & Gotchas

  • TArray is not thread-safe. Protect concurrent access with locks or use thread-safe alternatives.
  • Avoid storing raw UObject pointers in TArray across frames — use TArray<TObjectPtr<T>> or TArray<TWeakObjectPtr<T>> to cooperate with GC.
  • Reserve() upfront when you know the final size to avoid repeated reallocations.
  • Range-based for loops invalidate if you add/remove elements during iteration. Copy first or use a reverse index loop for removal.
  • RemoveAt() is O(N) unless you use RemoveAtSwap() which is O(1) but does not preserve order.

Examples

Common TArray operations C++
TArray<int32> Numbers;
Numbers.Reserve(10);         // Preallocate
Numbers.Add(1);
Numbers.Add(2);
Numbers.Add(3);
Numbers.Insert(99, 0);       // Insert at index 0

// Iteration
for (int32 N : Numbers)
{
    UE_LOG(LogTemp, Log, TEXT("%d"), N);
}

// Find
int32 Idx = Numbers.IndexOfByKey(2); // Returns 2 (after insert)
bool bHas = Numbers.Contains(99);    // true

// Remove (preserves order, O(N))
Numbers.Remove(99);

// Sort
Numbers.Sort([](int32 A, int32 B) { return A < B; });
UPROPERTY declaration C++
UPROPERTY(EditAnywhere, BlueprintReadWrite)
TArray<FString> Names;

UPROPERTY()
TArray<TObjectPtr<UMyObject>> ManagedObjects; // GC-safe

Functions (15)

Utility
13
Access Type Name
public function TArray::Add
public function TArray::AddUnique
public function TArray::ContainsByPredicate
public function TArray::Emplace
public function TArray::Find
public function TArray::FindByPredicate
public function TArray::Num
public function TArray::Remove
public function TArray::RemoveAll
public function TArray::Reserve
public function TArray::Reset
public function TArray::Sort
public function TArray::StableSort
Query
2
Access Type Name
public function TArray::Contains
public function TArray::IsEmpty

See Also

Version History

Introduced in: 1.0

Version Status Notes
5.6 stable
5.0 stable TObjectPtr support added for UPROPERTY arrays.

Feedback

Was this helpful?

Suggest an edit

Select a field above to begin editing.