How to convert enum to FString

Oct, 20 2021— #basic

In case you have UEnum:

UENUM()
enum EEnumExample : uint8
{
	SomeFieldOne,
	SomeFieldTwo
};

...

FString SomeString = UEnum::GetValueAsName(EEnumExample::SomeField).ToString();

Otherwise, you need to add DEFINE_ENUM_TO_STRING(<ENUM_NAME>) at the end of the enum. It's just a macro that automatically defines a function. You can then use the EnumToString function to convert the enum to FString:

#include "VisualLogger/VisualLoggerTypes.h"

enum EEnumExample
{
	SomeFieldOne,
	SomeFieldTwo
};
DEFINE_ENUM_TO_STRING(EEnumExample);

...

FString SomeString = EnumToString(EEnumExample::SomeField);
By Georgy Treshchev

Unreal Engine Developer. Contact for any questions.