RealDocs

TMap

struct Core Since 4.0
#include "Containers/Map.h"

Description

An associative container that maps unique keys to values. Backed by a hash set, so average-case Add/Find/Remove are O(1). Iteration order is not guaranteed.

Signature

template<typename KeyType, typename ValueType, typename SetAllocator, typename KeyFuncs> class TMap

Caveats & Gotchas

  • Keys must be hashable — implement GetTypeHash() for custom types, or use a type that already has one (FString, FName, int32, etc.).
  • TMap does not support duplicate keys. If you need multiple values per key, use TMultiMap.
  • The operator[] creates a default-constructed entry if the key doesn't exist. Use Find() when you don't want accidental insertion.
  • Cannot be used as a UPROPERTY directly with arbitrary key types — Blueprint-exposed maps must use supported types (FString, FName, int32, etc.).

Example

Basic add and lookup C++
TMap<FName, int32> ScoreMap;
ScoreMap.Add(TEXT("Alice"), 100);
ScoreMap.Add(TEXT("Bob"), 75);

if (int32* Score = ScoreMap.Find(TEXT("Alice")))
{
    UE_LOG(LogTemp, Log, TEXT("Alice: %d"), *Score);
}

Version History

Introduced in: 4.0

Version Status Notes
5.6 stable

Feedback

Was this helpful?

Suggest an edit

Select a field above to begin editing.