Description
Removes the element at Index, destructs it, and shifts all subsequent elements left to close the gap. A two-parameter overload accepts a Count to remove multiple contiguous elements at once.
Caveats & Gotchas
- • RemoveAt preserves the relative order of remaining elements by shifting, making it O(N - Index). If order doesn't matter, prefer RemoveAtSwap() which is O(1) for a single element.
- • Passing a Count of 0 to the multi-element overload is a no-op — no crash, no shrink, no work done. Passing Count < 0 or Index out of bounds triggers a RangeCheck assertion.
- • The bool bAllowShrinking overload is deprecated in UE 5.6 — use EAllowShrinking::No or EAllowShrinking::Yes instead.
- • All iterators and raw pointers into the array are potentially invalidated by RemoveAt, even if no reallocation occurs, because elements are relocated.
Signature
void RemoveAt(SizeType Index, EAllowShrinking AllowShrinking = UE::Core::Private::AllowShrinkingByDefault<AllocatorType>()) Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| Index | SizeType | Index of the element to remove. | — |
| AllowShrinking | EAllowShrinking | Controls whether the backing allocation is shrunk when slack becomes large. | UE::Core::Private::AllowShrinkingByDefault<AllocatorType>() |
Return Type
void Examples
Remove a single element by index C++
TArray<FString> Names = {TEXT("A"), TEXT("B"), TEXT("C")};
Names.RemoveAt(1); // Names is now {"A", "C"} Remove a contiguous range without triggering a shrink C++
TArray<int32> Values = {0, 1, 2, 3, 4, 5};
Values.RemoveAt(2, 3, EAllowShrinking::No);
// Values is now {0, 1, 5} See Also
Tags
Version History
Introduced in: 4.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?