Match the string type to the job
An identifier, a player-facing label, and a string being assembled are three different types.
#define LOCTEXT_NAMESPACE "Inventory"
// Identifier. Compared by index, never shown to a player.
static const FName PrimarySlotName(TEXT("Slot.Primary"));
// Player-facing. The key is what a translator receives.
const FText PickupPrompt = LOCTEXT("PickupPrompt", "Hold E to pick up");
#undef LOCTEXT_NAMESPACE
bool UInventoryComponent::HasSlot(const FName SlotName) const
{
// An index comparison, not a character walk.
return EquippedSlots.Contains(SlotName);
}
FString UInventoryComponent::BuildDebugLabel(
const FName SlotName,
const int32 Quantity) const
{
return FString::Printf(TEXT("%s x%d"), *SlotName.ToString(), Quantity);
}- Why
FNamecompares as an index, so a lookup costs the same regardless of length.FTextcarries the localization key that a translator needs.FStringis the only one of the three built for editing characters.- Costs
FNamecannot be modified and is case-insensitive on comparison, so it will not give user input back exactly as typed.FTextcannot be sorted or compared without knowing the active culture.- Instead
- Use
FStringViewwhen a function only reads an existing buffer and never stores it. UseFText::AsCultureInvariantwhen text has to bypass localization, such as a debug string.

