FName
#include "UObject/NameTypes.h" Description
An immutable, case-insensitive string stored in a global name table and identified by an integer index. Comparison and hashing are O(1) regardless of string length.
Caveats & Gotchas
- • Comparisons are always case-insensitive by default. 'MyActor' and 'myactor' are equal FNames. Use FString if you need case-preserving identity.
- • The name table is never shrunk — every unique string created as an FName lives in memory for the entire process lifetime. Avoid creating FNames dynamically from unbounded user input.
- • In Editor builds (WITH_CASE_PRESERVING_NAME), FName stores an extra display index to recover the original casing for ToString(). This makes FName larger in Editor builds than in cooked game builds.
- • NAME_None (default-constructed FName) compares equal to FName(TEXT("None")). This is intentional but can surprise you when storing a tag literally called 'None'.
- • FName hashing is fast but process-local and not stable across runs. Never serialize the raw integer index — always use ToString() or the FArchive operator<<.
Examples
Construction and comparison C++
FName WeaponTag(TEXT("Sword"));
FName SameTag(TEXT("sword")); // Equal to WeaponTag
ensure(WeaponTag == SameTag); // true
FString Str = WeaponTag.ToString(); Using as a TMap key C++
TMap<FName, int32> ItemCounts;
ItemCounts.Add(TEXT("Potion"), 5);
int32* Count = ItemCounts.Find(TEXT("potion")); // found — case-insensitive Tags
Version History
Introduced in: 1.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?