{ }Blueprint → C++

Unreal Engine 5 · Blueprint → C++

Array Contains & Find in Unreal Engine 5 C++UE Docs

The Blueprint Contains node maps to TArray::Contains, and the Find node maps to TArray::IndexOfByKey, which returns INDEX_NONE when the value is not present in Unreal Engine 5 C++.

Blueprint node & C++ equivalent

C++
bool bHas = Numbers.Contains(5);
int32 Index = Numbers.IndexOfByKey(5);   // INDEX_NONE if not found

What do the Contains and Find nodes do?

Contains answers a yes/no question: is this value somewhere in the array? Find returns the position of the first matching element so you can index into it. Both perform a linear search across the TArray.

The C++ equivalent

Numbers.Contains(5) returns a bool. To get the index, Numbers.IndexOfByKey(5) returns the position of the first element equal to 5, or the constant INDEX_NONE (which is -1) if nothing matches. Always test against INDEX_NONE before using the returned index.

Find by predicate vs by value

IndexOfByKey compares by value using operator==. When you need a custom condition, use IndexOfByPredicate with a lambda, or FindByPredicate to get a pointer to the element itself. Both also return INDEX_NONE or nullptr respectively on no match.

Frequently asked questions

How do you check if a TArray contains a value in UE5?+

Call MyArray.Contains(Value), which returns true if the value exists in the array.

What does IndexOfByKey return if the element is not found?+

It returns INDEX_NONE, a constant equal to -1. Compare the result against INDEX_NONE before using it as an index.

Related Arrays & Containers nodes

View all Arrays & Containers nodes →