RealDocs

TArray::Reset

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

Description

Removes all elements (calls destructors) but retains allocated memory for reuse. Faster than Empty() when the array will be repopulated immediately.

Signature

void Reset(SizeType NewSize = 0)

Parameters

Name Type Description Default
NewSize int32 Optional minimum capacity to retain. Defaults to 0. 0

Return Type

void

Caveats & Gotchas

  • Reset() retains the internal buffer — prefer it over Empty() in loops where the array is cleared and repopulated each frame, as it avoids repeated heap allocations.
  • Destructors are called for all elements. For arrays of pointers, this does not delete the pointed-to objects.
  • Empty() is the alternative that also releases memory. Use Empty() when the array is unlikely to be refilled.

Example

Reuse array allocation each tick C++
void AMyActor::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);

	// Reset preserves the buffer from last frame — no allocation
	VisibleEnemies.Reset();

	for (AEnemy* Enemy : AllEnemies)
	{
		if (CanSee(Enemy))
		{
			VisibleEnemies.Add(Enemy);
		}
	}
}

Version History

Introduced in: unknown

Version Status Notes
5.6 stable

Feedback

Was this helpful?

Suggest an edit

Select a field above to begin editing.