TArray::ContainsByPredicate
#include "Containers/Array.h"
Access: public
Specifiers: const
Description
Returns true if any element satisfies the predicate. Equivalent to FindByPredicate(Pred) != nullptr but more expressive when only a bool is needed.
Signature
bool ContainsByPredicate(Predicate Pred) const Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| Pred | Predicate | A callable returning true if the element matches the condition. | — |
Return Type
bool Caveats & Gotchas
- • O(n) linear scan. Stops at the first match.
- • If you also need the matched element or its index, use FindByPredicate() or Find() instead to avoid scanning twice.
Example
Check for a named item or a threshold condition C++
// Check if any quest is complete
bool bAnyComplete = Quests.ContainsByPredicate([](const FQuest& Q)
{
return Q.bIsComplete;
});
// Check if the player has a legendary item
bool bHasLegendary = Inventory.ContainsByPredicate([](const FItem& Item)
{
return Item.Rarity == EItemRarity::Legendary;
}); Tags
Version History
Introduced in: unknown
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?