{ }Blueprint → C++

Unreal Engine 5 · Blueprint → C++

Map (TMap) in Unreal Engine 5 C++UE Docs

The Blueprint Map maps to TMap in Unreal Engine 5 C++, storing key-value pairs. Use TMap::Add to insert, TMap::Find (which returns a pointer or nullptr) to look up, and TMap::Contains to test for a key.

Blueprint node & C++ equivalent

C++
TMap<FString, int32> Scores;
Scores.Add(TEXT("P1"), 10);
if (int32* Found = Scores.Find(TEXT("P1"))) { int32 V = *Found; }
bool bHas = Scores.Contains(TEXT("P1"));

What does the Map container do?

A Map associates unique keys with values, letting you look up a value quickly by its key. In Unreal Engine 5 C++ this is the TMap container, here declared as TMap<FString, int32> to map string keys to integer scores.

The C++ equivalent

Scores.Add(TEXT("P1"), 10) inserts or overwrites the value for key "P1". Scores.Find(TEXT("P1")) returns an int32* pointing to the stored value, or nullptr if the key is absent, so guard it: if (int32* Found = Scores.Find(TEXT("P1"))) { int32 V = *Found; }. Scores.Contains(TEXT("P1")) returns a bool without giving you the value.

Find vs FindRef vs operator[]

Find returns a pointer so you can distinguish a missing key from a stored zero. FindRef returns a copy of the value or a default-constructed value when the key is missing. operator[] requires the key to exist and will assert otherwise, so prefer Find when a key may not be present.

Frequently asked questions

How do you use a TMap in UE5 C++?+

Declare TMap<KeyType, ValueType>, insert with Add(Key, Value), and look up with Find(Key) which returns a pointer to the value or nullptr.

What does TMap::Find return when the key is missing?+

It returns nullptr. Always check the pointer before dereferencing it, for example if (int32* V = Map.Find(Key)) { ... }.

Related Arrays & Containers nodes

View all Arrays & Containers nodes →