RealDocs

FName::ToStringTruncate

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

Description

Converts the FName to a TCHAR buffer without heap allocation, truncating the result if the buffer is too small. Returns the length of the (possibly truncated) string excluding the null terminator.

Caveats & Gotchas

  • This function was introduced as the safe replacement for the deprecated raw-pointer ToString(TCHAR*, uint32) in UE 5.6. Prefer it over that overload to avoid buffer-overflow warnings.
  • If OutSize is smaller than FName::StringBufferSize (NAME_SIZE + 11 = 1035), the name will be silently truncated. A truncated name is not always detectable from the return value alone.
  • A templated overload ToStringTruncate(TCHAR (&Out)[N]) is also available and deduces N automatically — prefer it over the raw-pointer version when using a stack array.

Signature

uint32 ToStringTruncate(TCHAR* Out, uint32 OutSize) const

Parameters

Name Type Description Default
Out TCHAR* Output buffer to receive the null-terminated name string.
OutSize uint32 Number of elements in the output buffer, including space for the null terminator.

Return Type

uint32

Example

Write name into a small fixed stack buffer with truncation C++
TCHAR ShortBuf[64];
uint32 Len = MyName.ToStringTruncate(ShortBuf, UE_ARRAY_COUNT(ShortBuf));
// ShortBuf is now a null-terminated string of at most 63 chars
UE_LOG(LogTemp, Log, TEXT("Name (truncated): %s"), ShortBuf);

Version History

Introduced in: 5.6

Version Status Notes
5.6 stable Added in 5.6 as the safe replacement for the deprecated raw-pointer ToString overload.

Feedback

Was this helpful?

Suggest an edit

Select a field above to begin editing.