RealDocs

TArray::RemoveSingle

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

Description

Removes the first occurrence of Item from the array while preserving element order. Returns 1 if an element was removed, or 0 if Item was not found.

Caveats & Gotchas

  • Order-preserving removal is O(N) — it must shift all elements after the removed position one place to the left via RelocateConstructItems. If order does not matter, use RemoveSingleSwap instead, which is O(1) for the actual removal.
  • Only removes the first match. If the array may contain duplicates and you need all of them gone, use Remove (all, ordered) or RemoveSwap (all, unordered).

Signature

SizeType RemoveSingle(const ElementType& Item)

Parameters

Name Type Description Default
Item const ElementType& The item to search for and remove.

Return Type

SizeType

Example

Remove first occurrence of an actor pointer C++
TArray<AActor*> TrackedActors;
// ... populate ...
int32 Removed = TrackedActors.RemoveSingle(ActorToRemove);
if (Removed == 0)
{
    UE_LOG(LogTemp, Warning, TEXT("Actor was not in the tracked list"));
}

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.