FNames under the hood

I guess this is a question for someone-who-knows at Epic. But if you’re already using FNames like this and it works please let me know!

If I declare FName variables in a project, and then load DataTables with fields which are FNames, into other classes, will the same FNames be given the same index etc? Can I still use comparators like == at FName speed? Presumably a conversion takes place from string to FName, when the excel spreadsheet is loaded into the project. Does that mean the engine will see two different FNames, even if they are the same string?

Thanks!!

Internally FName uses an index into a string table. Two FNames made with the same string (ignoring case-variations as FName is case-insensitive) will generate the same string table index, which is what’s used by the FName == operator to compare them.

Note that you should not store FNames on disk or serialize them over the network. They are guaranteed to be unique only within the local process (not even on the same machine). When persisting or serializing FName fields, convert them from and to FString instead.

1 Like

Awesome! Thanks for all the info and suggestions, its a big help.

Some of our archivers have functions to automatically serialise/deserialise FNames in a persistent way (eg, ULinkerLoad, ULinkerSave, and UPackageMap) so if you’re using a custom archiver, feel free to take a look at how those handle FNames.

some clarification please: I’ve currently got save game data stored in maps keyed to FNames (mob stats keyed to the classes’ FNames, NPC disposition keyed to NPCs’ row names in data tables, chest contents keyed to level FName and chests’ object FNames, etc). Will this work, or do I need to find something else to use as the keys?

It’s bit an old question, but I am also confused to choose FName and FString.
Is it OK to use FName for replication all the time?? Or should I replace all the FName variables in the unreal struct replicated on the network to FString?

FNames are replicated just fine over the network. If they aren’t part of a special set of FNames hardcoded into the engine, they are automatically sent as FStrings. (You can find this logic in UPackageMap::SerializeName).

You don’t want to save to disk or replicate the ComparisonIndex or DisplayIndex of an FName because they change depending what objects are loaded and what order they are loaded into the engine.