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.

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

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.

I know this has been a few years, but figured I’d post my suggestion for others that come across this. Why not use a Struct?

UENUM(BlueprintType, Category = "Effects") 
enum Fire;
{
         Burning = 1,
         Smoking = 2
};

UENUM(BlueprintType, Category = "Effects") 
enum Ice;
{
         Chilled = 1,
         Snowflakes = 2
};

USTRUCT(BlueprintType, Category = "Effects")
 struct FEffectDisplay;
 {
         TArray<Fire> FireEffects = 1,
         TArray<Ice> SnowEffects = 2
 };

I’ve been in this problem before. My solution was to scrap Enums all together and build a static class hirearchy with static members.

struct EEffectDisplay { }  // Class is only being use for polymorphism

struct EFire : EEfectDisplay
{
    static int Burning = 1, Smoking = 2;
};
struct EIce : EEfectDisplay
{
    static int Chilled = 1, Snowflakes = 2;
};

And then the semantics look similar to enums, all though this cant be used as UENUM().

My question though is why does this need to be based in polymorphism? If you’re worried about Chilled being used for a campfire, then just do a check to make sure its a fire type. Have a function that returns a bool if the enum is fire, and use that.

This just doesn’t feel necessary.