FString vs FName vs FText

FString, FName, and FText are different data types for handling text, each with their own strengths.


FString (string)

Strings are used for mutable text, particularly when we need to perform actions like appending characters, replacing substrings, splitting text, etc. They're most often used for debugging, and internally Unreal creates string objects for log files and the output log.

Strings are great if:

  • You need to manipulate text (appending, replacing, splitting, etc)

FText (text)

The Text data type is used for user-facing content in the UI.

Texts are great if:

  • You need to display text in a UI
  • You need to localize text for different languages

FName (name)

Names are optimal when we're dealing with text comparisons and accessing data via keys because internally, Unreal hashes and stores FNames in a table alongside an index.

Names are great if:

  • You need to do text comparisons

Backlog

  • cover text literal macros available in C++ for localization, linked to a separate note on text localization (LOCTEXT, NSLOCTEXT, INVTEXT, etc)
  • cover text conversion safety between different text data types