C++ bitmask enums appear to be offset by 1
I created the following enum for use as a bitmask.
I then implement it as a public variable as follows.
This causes it to appear in the Details panel as follows:
The values may be selected with a check mark, permitting mixed flags as intended. However, when I evaluate the flags I get erroneous results. Outputting the value of Movement Tracking Flags as an integer shows that "None" is equal to a value of 1, "X" is equal to a value of 2, "Y" is equal to a value of 4, and "Z" is equal to a value of 16. This is despite their exact values being set explicitly as 0, 1, 2, and 4, respectively.
Please note that the value of "None" is designated as a requirement in the Unreal 4 Code Standard page.
asked Sep 16 '16 at 01:31 AM in C++ Programming
Ok - After talking to the Epic staff this appears to be the correct solution. Posting here so others can utilize this awesome feature!
Here is an example of how to declare a Bitflag enum:
Note that I'm not using the ENUM_CLASS_FLAGS macro any more. Instead I've created three macros that handle the testing for me:
And an example of me using this macro to test if an action is allowed:
UE-32816 is tracking the issue but as noted this is actually the designed behavior. You need to shift your enum value to do all of your testing, setting, and clearing.
answered Sep 22 '16 at 07:16 PM
As per UE-32816,
Fortunately, to get the OP's desired behaviour all you have since UE-32816 is add the following to the top of your enum declaration:
answered Nov 01 '18 at 07:25 AM
Follow this question
Once you sign in you will be able to subscribe for any updates here