Get Enum From String
Dear Community,
I’ve added a new entry to my UE4 C++ Enum wiki!
I am giving you the code to get an enum value back from a string, after it was initially converted to a string!
UE4 Wiki Link
emplate <typename EnumType>
static FORCEINLINE EnumType GetEnumValueFromString(const FString& EnumName, const FString& String)
{
UEnum* Enum = FindObject<UEnum>(ANY_PACKAGE, *EnumName, true);
if(!Enum)
{
return EnumType(0);
}
return (EnumType)Enum->FindEnumIndex(FName(*String));
}
//Sample Usage
EChallenge ChallengeEnumValue = //Initial Value
FString ParseLine = GetEnumValueAsString<EChallenge>("EChallenge", ChallengeEnumValue))); //To String
EChallenge Challenge = GetEnumValueFromString<EChallenge>("EChallenge", ParseLine); //Back From String!
Enjoy!