Description
Constructs a new element in-place at the end of the array using the provided constructor arguments. Avoids a copy or move compared to Add().
Signature
UE_FORCEINLINE_HINT SizeType Emplace(ArgsType&&... Args) Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| Args | ArgsType&&... | Constructor arguments forwarded directly to the element type's constructor. | — |
Return Type
int32 Caveats & Gotchas
- • Arguments are forwarded to the constructor directly — the element is constructed in the array's memory. This is more efficient than Add() when the element is non-trivial to copy or move.
- • Like Add(), may trigger reallocation. Reserve() beforehand if the final count is known.
- • Cannot be used with aggregate types that have no explicit constructor in older C++ standards — use Add() with a brace-initialised temporary instead.
Example
Construct structs directly in the array C++
TArray<FMyStruct> Items;
Items.Reserve(5);
// Calls FMyStruct(int32, FString) constructor in-place — no temp created
Items.Emplace(42, TEXT("Hello"));
Items.Emplace(7, TEXT("World")); See Also
Tags
Version History
Introduced in: unknown
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?