UENUM enum class with 256 values?

Hey,

It seems like it is impossible to have a enum class with 256 values in it (or even one value that is 255)


UENUM()
enum class EByte : uint8 {
  Mask = 255,
};

generates a error stating that EByte_Max cannot be automatically defined as 256 because it wraps to zero over 8 bits and that I should manually define it in the enum so…


UENUM()
enum class EByte : uint8 {
  Mask = 255,
  EByte_Max = 255,
};

generates an error stating that manually defined values must be greater than previously entered ones…

right now my hacky fix for this is below


#if CPP
#define EByte_Max Mask
#endif
UENUM()
enum class EByte : uint8 {
  EByte_Max= 255,
};
#if CPP
#undef EByte_Max
#endif

The above hack gets UHT to stop complaining when there are actually 256 values in the enum, and EByte::Mask exists still. The problem is that Mask does not show up as an option if the enum is a UPROPERTY (neither does EByte_Max, even if UMETA(DisplayName=“Mask”) is used afterwards.

So I was curious if I perhaps am doing something wrong or if when using enum class your really only limited to 255 values, 0…254?

Did you try using uint or uint32 istead of uint8 ? Does it compile that way?

Thanks for the reply,

I got an error stating that UENUM on “enum class” type can only be of uint8. I would need it to be 8 bits either way though

You’re not doing anything wrong. UENUMs silently insert an additional member after the last one, a sort of sentinel value used for reflection I assume. So if “slot 255” is already occupied, UHT will complain about it.

Well that’s painful, but thanks for the response! Would be nice if they could fix it. Seems like they could just treat E…_MAX == 0 special, since your not allowed to have any enum types that are not unsigned 8 bit integers internally and your also not allowed to UENUM an enum with no entries in it.