RealDocs

TArray::FindByPredicate

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

Description

Returns a pointer to the first element for which Pred returns true, or nullptr if none match. A const overload returning a const pointer also exists.

Signature

ElementType* FindByPredicate(Predicate Pred)

Parameters

Name Type Description Default
Pred Predicate A callable returning true for the element to find.

Return Type

ElementType*

Caveats & Gotchas

  • Returns a raw pointer into the array's internal storage. The pointer is invalidated by any operation that reallocates the array (Add, Remove, etc.). Do not store it across mutations.
  • Returns nullptr on no match — always null-check before dereferencing.
  • For a bool result without needing the element itself, ContainsByPredicate() is more expressive.

Example

Find first enemy below half health C++
AEnemy* Target = Enemies.FindByPredicate([](const AEnemy* E)
{
	return IsValid(E) && E->Health < E->MaxHealth * 0.5f;
});

if (Target)
{
	FocusTarget(Target);
}

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.