Download

Name vs String, some help needed.

Hello all. I was reading that Name is more lightweight than String, but according to the wiki Name is “immutable”. To my understanding this means it can’t be changed once created. However I made a small test changing a Name variable during run-time and it seems to work fine. It seems like I am missing here, can someone explain me what “limitations” there are in Names ? I was always using String but it seems it might be better to change them to Name for Performance, except when saving data. Any insight would be appreciated.

AFAIK the blueprint implementation hides the immutable nature of the underlying FName type. If you a assign a Name variable a new value, a new C++ Fname will be created for it. The immutability is still present in the sense that the range of nodes for manipulating the content of String is not available for Name.

  • If you have a sequence of characters that will not be manipulated (often a name, id or key for something) use Name.
  • If you are going to manipulate the content (split, add, replace character, etc.) use String.
  • For everything that will be displayed to the user, use Text as it among other things makes localisation easier.

(Under the hood name is actually just an id, referring to a table containing all the created name variables and the strings they represent. In this way only the short id needs to be sent around the engine or over the network. This also means you should never directly serialize a name for storage, but I think standard blueprints always hides that from you. For example, I’m quite sure nodes working on SaveGame contains a built in conversion to/from string.)

Ah I see, thank you!