I am trying to add a ToString function to my custom Enum in C++ because if I use Blueprints I can convert my custom enum to string. C++ the only way I found from other header files was like this (without the UENUM macro)
Alive UMETA(DisplayName = "Alive"),
Dead UMETA(DisplayName = "Dead")
inline const TCHAR* ToString(EKaoriGameUnit::Type State)
Since I want to use this or other Enums later in Blueprints I added the UENUM macro but now the UHT throws this error
KaoriGameTypes.h(10): error : In TemporaryUHTHeader_KaoriGameTypes: Missing ‘}’ in ‘Enum’
If you are willing to try an alternative you can make a BlueprintFunctionLibrary for yourself that will do the same as your function does.
Keep in mind blueprint function libraries can be used anywhere! Even in anim blueprints! anywhere!
so it is not that much of an issue
You’re just declaring the enum strings in a different but absolutely blueprint global context
I think of this as skipping a step because you’d need to write up some sort of BP interface for your proposed Enum function anyways. But now it is instantly BP global and you dont have to write it twice
You can also use the static blueprint functions in any .cpp file like any other static library functions
That is definitely something to consider at a later point thanks, but for now I need a way to get the Text representation for my enum. What I did in Blueprints was searching the level for camera actors (I tagged them with a specific text value) belonging to the team of the player.
I was trying the same in C++ but there is no function to convert an Enum value to string
The UENUM parsing of a namespace gets rather cranky if you have something other than just the Enum in it. You can do this instead to get the same behavior in terms of the namespacing but with functional compiling!