Using Enum Value In Property Meta Data Does Not Compile

So I am trying to set a key value pair in a UPROPERTY Metadata section, where the value is a enumeration-value:

UPROPERTY(BlueprintReadOnly, Category = "Output", Meta = (Unit = EUnits::Percentage))
	float ChargingStatus = 0.f;

The enum is defined like this:

UENUM()
enum class EUnits : uint8 {
	Percentage,
	Seconds
};

This code does not compile, I get this error:

Error C:/Workspaces/Unreal Engine 4/TheSpaceGame/Source/TheSpaceGame/GaussCanonModule.h(45) : Error: Missing ‘)’ in Variable declaration specifier

(line 45 is the UPROPERTY(BlueprintReadOn… line)

which is not very helpfull. If I substiute the Enum Value with an integer literal for example it works. Does that mean that enums are not suppoerted in the meta data of a property? If so, is there a workaround, or will I just have to use some defines maybe to get a literal value in there?

I’m looking forward to your help!

EDIT:

And it gets better. Defines don’t work either (maybe a macro in a macro causes problems?) It does compile but, when I use

it2->GetINTMetaData("Unit")

It just returns 0. I am now at the stage, where I put in integer literals, which defeats the whole point of enumerations. There has to be a better way.

Well it’s been some time now … I hoped that someone from Epic would have a look at this, since the community doesn’t seem to know much about this.

Out of curiosity, have you tried using removing the “class” modifier from your enum (thus making it effectively just an int in disguise)? Enum Classes are a C++11 thing that enforce type safety so I could see that causing issues.

Out of curiosity, have you tried using removing the “class” modifier from your enum (thus making it effectively just an int in disguise)? Enum Classes are a C++11 thing that enforce type safety so I could see that causing issues.

You are right, it works like this now:

UENUM()
enum EUnits {
	None = 0,
	Percentage = 1,
	Seconds = 2
};

I then had to change all the enum members that I had to TEnumAsBytey but thats not a big deal.

Although now I found this under the coding standards:

Enum classes should always be used as a replacement for old-style namespaced enums, both for regular enums and UENUMs.

These are also supported as UPROPERTYs, as long they are based on uint8 - this replaces the old TEnumAsByte<> workaround:

So my workaround cannot be intended by Epic. I suspect a bug.