Since version 4.10 the GetEnumText return the enum as Text and not the DisplayName.
Having the following enum definition.
/** @brief Equipment types. */
UENUM(BlueprintType)
enum class EKEquipmentType : uint8
{
ET_Undefined UMETA(DisplayName = "Undefined"),
ET_OneHand UMETA(DisplayName = "1-Hand"),
ET_TwoHand UMETA(DisplayName = "2-Hand"),
ET_OffHand UMETA(DisplayName = "Off-Hand"),
ET_Head UMETA(DisplayName = "Head"),
ET_Shoulders UMETA(DisplayName = "Shoulders"),
ET_Neck UMETA(DisplayName = "Neck"),
ET_Wrists UMETA(DisplayName = "Wrists"),
ET_Hands UMETA(DisplayName = "Hands"),
ET_Finger UMETA(DisplayName = "Finger"),
ET_Torso UMETA(DisplayName = "Torso"),
ET_Waist UMETA(DisplayName = "Waist"),
ET_Legs UMETA(DisplayName = "Legs"),
ET_Feets UMETA(DisplayName = "Feets")
};
This function
inline FText UKAttributeHelper::GetEquipmentTypeEnumAsText(EKEquipmentType EnumValue)
{
const UEnum* EnumPtr = FindObject<UEnum>(ANY_PACKAGE, TEXT("EKEquipmentType"), true);
if (!EnumPtr)
return DKT_GEN_INVALID;
auto index = EnumPtr->GetIndexByValue((uint8)EnumValue);
return EnumPtr->GetEnumText(index);
}
returns the type.
If I call the function with EKEquipmentType::ET_Head it returns “ET_Head” and not “Head”. It was not the case in previous versions.
I’ve check the source code and the code for returning the DisplayName is conditionned with preprocessor WITH_EDITOR.
FText UEnum::GetEnumText(int32 InIndex) const
{
#if WITH_EDITOR
//@todo These values should be properly localized [9/24/2013 justin.sargent]
FText LocalizedDisplayName = GetDisplayNameText(InIndex);
if(!LocalizedDisplayName.IsEmpty())
{
return LocalizedDisplayName;
}
#endif
return FText::FromString( GetEnumName(InIndex) );
}
Is there another way to get the DisplayName ?
Txs for your help,
D.