Using UEnum::GetValueAsString to get an enum class value

Using UEnum::GetValueAsString to get an enum class value results in a warning:

"EnumAsByte.h(20): [C4996] 'TEnumAsByte_EnumClass<true>': TEnumAsByte is not intended for use with enum classes - please derive your enum class from uint8 instead. Please update your code to the new API before upgrading to the next release, otherwise your project will no longer compile."

Example code

Enum:

UENUM(BlueprintType)
enum class EResourceType : uint8
{
	Money,
	Population,
	MarketSentiment
}

Use:

FString const ResourceString = UEnum::GetValueAsString<EResourceType>(ResourceType); // ResourceType is of type EResourceType. 

GetValueAsString overloads: GetValueAsString | Unreal Engine Documentation

The enum is derived from uint8. How does one get the values as string from an enum class?

Thanks.

1 Like

Try this:

const FString ResourceString = StaticEnum<EResourceType>()->GetValueAsString(ResourceType);
3 Likes

Thanks for your help! This has indeed resolved the warning.

Templated reflected type accessors look very useful.

Could you or anyone elaborate on why my original method seemed to use the wrong overload? It seemed to use this instead of this.

Thanks.