Conversion of Enum to String
Hello, So I have been trying to convert my Enumeration values to an FString.
I followed this post: https://wiki.unrealengine.com/Enums_For_Both_C%2B%2B_and_BP
and ended up with this:
This is not working though, something about unresolved externals. I am sure I am making some mistake somewhere, and if someone could help me with it, that would be great.
asked Nov 08 '15 at 09:49 PM in C++ Programming
For the people that dislike the string parameter, I found a solution to this. I didn't like the string because it would present problems when refactoring (renaming) the enum.
The stringify macro literally converts the characters of its input to chars. this works great and it will refactor the enum because it's now used as a type instead of a string. I hope this helps anyone.
Using the info from both of these posts I wrote the following function that works:
And I just put it in a header file along with my enums. Thanks yall!
answered Sep 01 '17 at 05:57 AM
Missing A Few Heads
If you'd like to do this without creating a function to convert the enum, here's a simple way to use the method outlined above:
The first line finds a pointer to the enum object from its namespace, and then in the UE_LOG call, we use that enum pointer to get a string value to output. Important to note is that the pointer isn't guaranteed to be valid, so use a ternary operator to ensure that you safely handle a case where the pointer doesn't exist.
This UE_LOG statement also supplies an example of grabbing a string from an enum that isn't enclosed in a namespace and whose path is known.
answered Oct 07 '16 at 10:44 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here