Download

UENUM does not allow having negative values

Hello,

so the question is in the title: Why does UENUM not allow having negative values? I want something like this:



UENUM()
enum Direction {BACKWARD = -1, STOP = 0, FORWARD = 1};

But when I compile I see the error: Explicitly specified enum values must be greater than any previous value and less than 256
It is thrown from HeaderParser.cpp:700



int32 NewEnumValue = 0;
...
if ((NewEnumValue < CurrentEnumValue) || (NewEnumValue > 255))

Why is that? Can I work around this?

UENUM enums use unsigned 8-bit integers (uint8) which cannot be negative values. Valid values range from 0 to 255.

If you need to temporarily have a byte as a negative number, say for menu switching where the negative number will then be switched to the highest value in a set, just convert it to an integer. Bytes can not be negative.

IE: You have 4 menu elements, and you want to select those menu elements via controller. So you de-inc your EBMenu by 1, then check if it is less than 0, then go to 3, however, it will flip out and set to 255 during the check. You can temporarily convert it to an int to do the check and set to 3, before converting the int to a byte.

Thanks, well I decided to just remove UENUM modifier since I am not going to use that particular enum in Editor.