RealDocs

TArray::EmplaceAt

function Core Since 4.14
#include "Containers/Array.h"
Access: public

Description

Constructs a new element in-place at the given index, shifting all subsequent elements right by one. Avoids a temporary copy compared to Insert.

Caveats & Gotchas

  • Inserting at any position other than the end (Index == Num()) requires shifting all following elements, which is O(N). For order-insensitive use cases, prefer EmplaceAt with the last index or just Emplace to avoid the shift cost.
  • Index must be in the range [0, Num()] — inserting past the end asserts. Use Emplace (no index) to append.

Signature

template <typename... ArgsType>
UE_FORCEINLINE_HINT void EmplaceAt(SizeType Index, ArgsType&&... Args)

Parameters

Name Type Description Default
Index SizeType The index at which to insert the new element. Existing elements at and after this index are shifted right.
Args ArgsType&&... Arguments forwarded directly to the element's constructor.

Return Type

void

Example

Insert a constructed element at the front C++
TArray<FHitResult> Hits;
// ... populate Hits ...
Hits.EmplaceAt(0); // default-constructs an FHitResult at index 0, shifting all others

Version History

Introduced in: 4.14

Version Status Notes
5.6 stable

Feedback

Was this helpful?

Suggest an edit

Select a field above to begin editing.