RealDocs

TArray::Push

function Core Since 4.0
#include "Containers/Array.h"
Access: public Specifiers: inline

Description

Appends an element to the end of the array, identical in behaviour to Add(). Exists as a named alias for stack-idiom code that pairs with Pop().

Caveats & Gotchas

  • Push is a thin wrapper around Add() — there is no difference in allocation behaviour, return value, or performance. Prefer Add() when the stack metaphor doesn't apply, to signal intent clearly.
  • A const-ref overload also exists — Push(const ElementType& Item) — for lvalue arguments. The move overload is preferred when passing temporaries to avoid an unnecessary copy.

Signature

UE_NODEBUG UE_FORCEINLINE_HINT void Push(ElementType&& Item)

Parameters

Name Type Description Default
Item ElementType&& The element to append to the end of the array.

Return Type

void

Example

Using Push/Pop as a stack C++
TArray<AActor*> ActorStack;
ActorStack.Push(GetOwner());
ActorStack.Push(SomeOtherActor);

while (!ActorStack.IsEmpty())
{
    AActor* Current = ActorStack.Pop();
    ProcessActor(Current);
}

Version History

Introduced in: 4.0

Version Status Notes
5.6 stable

Feedback

Was this helpful?

Suggest an edit

Select a field above to begin editing.