RealDocs

TArray::InsertZeroed_GetRef

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

Description

Inserts a single zero-initialized element at Index and returns a reference to it, allowing immediate field-by-field initialization without a second array lookup.

Caveats & Gotchas

  • The returned reference is marked UE_LIFETIMEBOUND — it becomes invalid after any operation that reallocates the array (Add, Reserve, further insertions, etc.). Never store this reference across array mutations.
  • No constructor is called — the element is zeroed via Memzero. Only safe for POD-like types where zero is a valid initial state; for types needing construction, use InsertDefaulted_GetRef().

Signature

ElementType& InsertZeroed_GetRef(SizeType Index) UE_LIFETIMEBOUND

Parameters

Name Type Description Default
Index SizeType Position at which to insert the new element.

Return Type

ElementType&

Example

Insert and partially initialize a struct in one step C++
struct FSimpleRecord { int32 Id; float Value; };
TArray<FSimpleRecord> Records;
Records.SetNum(3);

FSimpleRecord& NewRec = Records.InsertZeroed_GetRef(1);
NewRec.Id = 42;
NewRec.Value = 3.14f;

Version History

Introduced in: 4.20

Version Status Notes
5.6 stable

Feedback

Was this helpful?

Suggest an edit

Select a field above to begin editing.