EnumToString Macro - Epic Wiki

# EnumToString Macro

# Contents

# Overview

Macro that lets you quickly get an enum value as a FString for use in logging etc.
Caveat - only works with enumerators defined using UENUM() macro.

# YourProject.h

#define GETENUMSTRING(etype, evalue) ( (FindObject(ANY_PACKAGE, TEXT(etype), true) != nullptr) ? FindObject(ANY_PACKAGE, TEXT(etype), true)->GetEnumName((int32)evalue) : FString("Invalid - are you sure enum uses UENUM() macro?") )

# Usage

# YourClass.h

UENUM() enum class EUsesEnum : uint8 { UseEnum_Bad, UseEnum_Good, UseEnum_Nice, UseEnum_Naughty };

# YourClass.cpp

void AYourClass::SomeFunction() { EUsesEnum UseEnumValue = EUsesEnum::UseEnum_Good; UE_LOG(LogSomething, Log, TEXT("UseEnumValue as string : %s"), *GETENUMSTRING("EUsesEnum", UseEnumValue)); }

Output:
LogYourCategory: UseEnumValue as string : UseEnum_Good

# Credits

Kris

Retrieved from "https://wiki.unrealengine.com/index.php?title=EnumToString_Macro&oldid=14099"

Category: