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:
Because of reflection system code need to know what type of enum you looking for…
You can do this using strings… Rama did a very good wiki page and described some usefull methods to get enums by strings using a template function…
Sadly that doesn’t really answer my question. Once I’m in template code and only have the typename template parameter there is no way that I know of to convert this into a string matching the typename as it is used by the Rama there.
static_assert(TIsEnum<EnumType>::Value, "Should only call this with enum types");
UEnum* EnumClass = StaticEnum<EnumType>();
check(EnumClass != nullptr);
Which does seems to fit our “convert static c++ type in UEnum instance” request, and with the ability to do error checking !