Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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:

 namespace EEffectDisplay
     UENUM(BlueprintType, Category = "Effects") enum class Fire : uint8
         Burning = 1,
         Smoking = 2
     UENUM(BlueprintType, Category = "Effects") enum class Ice : uint8
         Chilled = 1,
         Snowflakes = 2

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:

 if (EffectDisplay == EEfffectDisplay::Fire::Burning)
     {///create icon, add fire particles, etc...}
 else if (EffectDisplay == EEfffectDisplay::Ice::Snowflakes)
     {///Make snowflakes, etc...}

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.

Product Version: UE 4.20
more ▼

asked Aug 31 '18 at 11:40 PM in C++ Programming

avatar image

Dragon Slave
43 4 7

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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

more ▼

answered Sep 01 '18 at 01:34 AM

avatar image

37.2k 936 172 1116

avatar image Dragon Slave Sep 01 '18 at 06:48 AM

Thanks a lot for this informative reply. What I gather from your answer is that it is basically not possible to combine enumerations like this. I'll look into the alternatives you suggested.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question