DanaFo
(DanaFo)
April 30, 2015, 5:37am
1
I’ve noticed a few UEnum methods ask for EnumPath ie:
static FString GetValueAsString
(
const TCHAR * EnumPath,
const T EnumValue
)
(From: UEnum::GetValueAsString | Unreal Engine Documentation )
What exactly does that syntax look like?? There is literally nothing I can find that explains this.
Thanks!
Rama
(Rama EverNewJoy)
April 30, 2015, 8:59am
2
TCHAR * is the Inner Type of FString
Hi there!
You can just make an FString and use the FString::Operator* to access the FString’s inner data type which is TCHAR*!
FString YourPath = "Your Happy Path Now That You Read This";
GetValueAsString<EnumType>(*YourPath,EnumValue);
Rama
DanaFo
(DanaFo)
April 30, 2015, 2:35pm
3
Ok that makes more sense, but is this specifically for returning the enum’s path, and is that like a harddrive path? Is it related to the object inheritance of the enum (like UObject?) Thanks again for your time!
DanaFo
(DanaFo)
May 1, 2015, 5:03pm
4
Is this one of the unsolved mysteries of the unreal programming universe?
Acrossfy
(Acrossfy)
June 9, 2015, 4:18pm
5
In many cases this path fits with the following template – “ClassName.EMyEnumType”. But in some cases it doesn’t work. For example:
UEnum::GetValueAsString(TEXT("MyGameMode.EModeExampleEnum"), EGameModeExampleEnum::FIRST)); //it works
UEnum::GetValueAsString(TEXT("MyPlayerController.EControllerExampleEnum"), EControllerExampleEnum::FIRST)); //it works
UEnum::GetValueAsString(TEXT("MyCharacter.ECharacterExampleEnum"), ECharacterExampleEnum::FIRST)); //it crashes
If you look inside the GetValueAsString method, you will see how it works:
UEnum* EnumClass = FindObject<UEnum>(nullptr, EnumPath);
UE_CLOG(!EnumClass, LogClass, Fatal, TEXT("Couldn't find enum '%s'"), EnumPath);
return EnumClass->GetEnumText(Value);
This way to find enum pointer isn’t good for any case. So the best way to find pointer and get enum value as string is:
const UEnum* EnumPtr = FindObject<UEnum>(ANY_PACKAGE, TEXT("ECharacterExampleEnum"), true);
if (EnumPtr)
{
auto EnumName = EnumPtr->GetEnumName((int32)ECharacterExampleEnum::FIRST);
}
Andrew
DanaFo
(DanaFo)
June 10, 2015, 1:17am
6
Awesome, that totally makes sense now, thanks for your time!