How to retrieve UEnum by Type?

DaDummy
Tue, 27 Feb 2018 18:39:35 +0000
Rendering

When I define an UEnum in C++ like this:

UENUM(BlueprintType)
enum class EMySampleEnum : uint8
{
	One,
	Two,
	Three
};

I’d like to be able to access its static UEnum instance like I’m used to with UStruct and UClass where a call to the ::StaticClass() member suffices to do this in a typesafe with no weird and error prone string hashing magic going on my side at least. As far as I can tell there is some code related to this generated in *.gen.cpp for hot reload purposes I suppose, but this doesnÄt seem to be accessible from the outside.

Is there a nice way to access the static UEnum instance corresponding to an enum type I have at hand?

I can’t use defines for this as I want to use this within templates aswell and defines are resolved before template parameters are.

In other words I’m looking for an implementation of GetStaticUEnum that could be used as follows:

template<typename T>
int32 GetMaxValue()
{
    return GetStaticUEnum<T>()->GetMaxEnumValue();
}

6 posts - 5 participants