RealDocs

FName::SetNumber

function Core Since 4.0
#include "UObject/NameTypes.h"
Access: public

Description

Changes the numeric suffix of an FName without altering its string part. Useful for incrementing an instance number while keeping the base name.

Caveats & Gotchas

  • FNames are case-insensitive and share string storage via the global FNamePool. SetNumber does not create a new pool entry — it only changes the in-place number field, so this is cheap but mutates the existing FName value.
  • The number stored internally is offset by 1 from the displayed suffix. Number == 0 means no suffix; Number == 1 displays as "_0". This is a common source of off-by-one confusion when generating numbered names.
  • When UE_FNAME_OUTLINE_NUMBER is defined (the default in 5.x), the number is stored separately from the index and this call goes through CORE_API. The inline FORCEINLINE path is only compiled when the outline number is disabled.

Signature

void SetNumber(const int32 NewNumber)

Parameters

Name Type Description Default
NewNumber const int32 The new numeric suffix to assign. 0 means no numeric suffix in the display string.

Return Type

void

Example

Generate a sequence of numbered FNames for spawned actors C++
FName BaseName(TEXT("SpawnedActor"));
for (int32 i = 0; i < 10; ++i)
{
    FName InstanceName = BaseName;
    InstanceName.SetNumber(i + 1); // Displays as SpawnedActor_0, _1, ...
    SpawnActorWithName(InstanceName);
}

Version History

Introduced in: 4.0

Version Status Notes
5.6 stable

Feedback

Was this helpful?

Suggest an edit

Select a field above to begin editing.