Enum to String in Unreal Engine: How I Learned to Stop Hardcoding and Love Type Safety

Image for post
Image for post
Just imagine she is searching for the right strings.

Intro

Setup

API Example

Now press button ‘Make implementation plz!’

Type safety

Using FindObject with hardcoded enum type.

Function call context

Macro defintion for CurrentFunctionName
Image for post
Image for post
Signature returned by the macro using MSVC: “class FString __cdecl BIQ::Util::GetNativeTypeName<enum EWlanNotificationMSM>(bool)”
Stripping the function signature down to its template argument.

Tying it all together

Enum Value Template Class

Template class, housing the actual stringification magic ✨
Mate, let the compiler figure it out ;)

Today’s impossible, will be tomorrow’s reality. https://think-biq.com

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store