Create a nested enum with a single variable of parent class able to take values of both child enum classes
I'm trying to create an enum for a C++ part of my code, to pass to the UI which will then create an on-screen icon and possibly visible particle effects on the character. Because there may be a large number of these icons (more than 256) and because I want to organize them, I want to create an enum of the form A::B::C.
I wrote the following code:
My intended implementation would then be able to read the EffectDisplay variable from each effect and then show the icon based on that. It would look something like this:
Obviously with hundreds of these I would want to use a spreadsheet or read these from a data file, but that's the basic idea.
But this basically doesn't work. C++ won't let a single variable to store values EEffectDisplay::Fire::Burning and EEffectDisplay::Ice::Snowflakes. So I am pretty much stuck.
Also these two enumerations don't seem to appear in blueprint.
asked Aug 31 '18 at 11:40 PM in C++ Programming
First of all this is valid for C++, what stops it is UnrealHeaderTool (which reads all those UENUM macros) that probably prevent you from compiling, it does support enum in namespace but UENUM need to be before namespace deceleration, still you can have only one enum in it (it for all those ESomething::Type enums). I also think you missing enter after UENUM. Also UE4 does not explosively support namespace in reflection system expect the enums.
Still your code is valid in C++ outside UENUM and UE4 reflection system, but there issue in your method, namespaces don't carry any information, namespaces are just as it say... to creating namespace for other types, but it does not contain any data, so you won't be able to recognize diffrence between EEfffectDisplay::Fire and EEfffectDisplay::Ice and you can not use namespace as type and to make things worse you put exact same numbers on both enums so you can't even difference on integer data that those enums carry.
In your place i would at least create a struct containing 2 enum values (or enum and integer), with that we got type for icon and then effect, with that you can do some magic, with structure you can make custom editor UI allowing to do proper selection that you want:
You could do some cast overload magic with uint16 and combine both 8-bit values to single variable and store in data tables if you want to
Other solution would just use reflected uint16 and create non-reflected enums with namespace you trying to do and make them hold uint16 values, but those would complicate not only custom UI for editor route abut laso make variable unusable in Blueprint as uint16 in not directly supported in blueprints. Or else you gonna armor the uint16 with struct. and do some magic trickery to make it usable in blueprint
answered Sep 01 '18 at 01:34 AM
Follow this question
Once you sign in you will be able to subscribe for any updates here