FYI,
Fulezi’s solution and my solution above will both get the result, but there is one minor difference. Fulezi’s answer will return a fully scoped result, whereas my solution will drop the enum class scope.
For example:
FString Name1 = EnumToString< ENoiseAlgorithm >( ENoiseAlgorithm::FBM );
Name1 would be “FBM”
FString Name2 = UEnum::GetValueAsString( ENoiseAlgorithm::FBM );
Name2 would be “ENoiseAlgorithm::FBM”
Which one you should use really depends on what your needs are.
Edit: I have discovered a bug in my version. As it was originally written, my version of this function will require you to order your enum values from 0 upwards and by increments of 1. This was fine for most use cases, but should you need to order them with gaps in the values or out of order for some reason, then my original solution will give you the wrong result.
For example:
UENUM( BlueprintType )
enum class EMenuStackLocation : uint8
{
None = 0xFF UMETA( Hidden ),
BottomMost = 0,
Default = 1,
TopMost = 2,
Count UMETA( Hidden ),
};
for this:
FString Name = UEnum::GetValueAsString( EMenuStackLocation::TopMost );
We get “EMenuStackLocation::TopMost”
But for this:
FString Name = EnumToString( ENekoUIMenuStackLocation::TopMost );
We get “Count”, which is incorrect.
If we reorder the None value to be at the end of the list after Count, then it will work fine (provided we don’t have value gaps between our enum constants, i.e. TopMost = 10 or something.)
My code can be fixed by changing the GetNameStringByIndex() to GetNameStringByValue(). I have corrected it in my post above as well.