Integer to enum(byte) with strange casting result

Hi,
Just updated to UE 4.9 and I have a problem with casting int to byte & enum in bp.

TL;DR version: casting 0,1,2(int) to enum failed, and results of casting enum to int are 2,4,6(should be 0,1,2).

Detailed post:

As you can see in following pictures, I have a enum with 3 items.

And I’m casting random int to byte then enum to get a random item list.

First I was using old way, random generate an integer in range of 0~2.

result is like this:

56596-result012.png

enum casting failed except for Paper(2).

I cast & printed other enums and found that enum are cast to 2,4,6, not 0,1,2(I thought they would be).

Then I tried to random my integer within range of 1~3, but still no use:

56595-result_nox2.png

So I multiply my int rand result with 2(so they would be 2,4,6) and still got wrong result.

int to byte conversion is even much weird in this case,

56593-result.png

My enum is like this:

56594-enum.png

And bp setup. (This is captured with int x 2)

Can you help me with this issue? Thanks. :slight_smile:

Update:
I tested in my old project in 4.8 and have no issue.
enums in 4.8 is using 0~2, casting results are all correct.

Update 2: Created a new C++ based project in UE 4.9 with same condition, and enum casting is incorrect.
So it looks like a bug only in 4.9.

This scare me because I’ve to convert a project with at least 30 different enums today…

BTW: if you use this setting is still bugged?

(and P.S: if you know a way to get back literal enum directly in select tell me how, I hate it so much since 4.8…)

EDIT: miserable fail in random integer. Set 2, not 3.

Hi,

I tried your pic and result is quite interesting.

Console output is correct for enum name, but still got 2,4,6 for int casting.

56618-result.png

But if I choose actual actor in scene and check detail panel, it showed invalid , and order of item is also not right(can compare with previous pic), I guess this might be a display bug.

56619-playdetail.png

My bp graph:

As for literal enum with select, I don’t have a better solution either, I guess this is only proper way at moment. :slight_smile:

Add a new set of pics for more clear comparison.

56626-result2.png

56627-playdetail2.png

Looks like it treats paper and stone as invalid, and cut as paper.

Enum order:

56628-enum+order.png

Hey CrispyVitamin,

I’m having some trouble reproducing this, but I may not be clear on your repro steps. Can you set this up in a new project? If so, please upload it somewhere and get me a link so I can take a look. Otherwise, some clear numbered steps to take to reproduce would be much appreciated. Thanks!

Hi, thanks for reply.

I’ve uploaded an UE 4.9 blank bp project with bugged bps(I recreated them in this new blank project).

Link: Dropbox - BlankEnumTest.7z - Simplify your life

Open project and it should loads test map, hit play and you can see test result in console like following pic.

Hey CrispyVitamin,

Thanks for test project! I was able to narrow this down to Enum to Byte conversion in 4.9.0, and I’ve entered a bug report for issue (UE-20643). I’ll post here when I see any update. Thanks for report!

@Iohoilpotere Updating I think you should be fine. I updated my project and ENUM’s I already had in place still operate as they should. It’s only when I try to create a new one that my problems occur.

Is there any way to track progress on a bug?

Not currently, though we’re taking steps to make our bug tracking software public (and vote-able). These sorts of bugs take time, so I wouldn’t expect a fix to be implemented for 4.9.

Thanks for reply. That would be great to be able to track bugs.
Regarding your comment on this being fixed in 4.9, it doesn’t really make sense.

This is a major issue as it means no project using blueprints can continue using ENUMS until this issue is fixed. Am I missing a work around? (other than converting all enums to INTs)

Hot fixes are reserved for editor crashing bugs and like. It’s always possible that something will be added to a hotfix if it’s a simple enough adjustment and developers are able to sneak it in, but that’s not common.

Enums are working fine, it’s simply a matter of Enum to Byte converter returning wrong value (2, 4, 6, etc, rather than 0, 1, 2), and that’s in a predictable pattern. If you absolutely need byte value for an enumerator, as in case above, for now you can work around it by adding 1 and then multiplying by 2.

Ok thanks.
I’m not sure if you are aware of this but setting blackboard value of a Behavior Tree (Enum) also causes same problem.

So I think there is a conversion between BP and BT that has same effect and thus if you look at value on BT it says ENUM MAX.

Hi ,

I’ve done some additional tests today, and found that use selection method to set enum item is also bugged. (Test Event 2 in test project)

Only workable way to set enum is to set it directly in node or in detail panel. (Test Event 3 in test project)

And this greatly reduced usability of enums because it limits run-time manipulation of enum variables.

It would be greatly appreciated if you can fix this in 4.9. :slight_smile:

Also, here’s my updated test project if you need: Dropbox - BlankEnumTestV2.zip - Simplify your life

And some screenshots:

EnumArray2 is using select method and it’s broken, only EnumArray3 is correct(set directly in node).

56820-test2-3result.png

Yep, that’s same problem. Select node is performing an Enum to Byte conversion. reason second method works is because no conversion is taking place (you’re dealing strictly with enums, not bytes). I’ll add your notes to bug report.

Your workaround is good, and as I mentioned above, you can still use integers to set as long as you do a manual conversion ((x + 1) * 2).

Yea, this will happen anytime there’s a conversion from Enum to Byte, as far as I can see. I’ll add this note to bug report. Thanks!

Here’s a simple workaround I’m using to generate random enums with correct value thanks to multiple return function in 4.9. :slight_smile:

Have a look if you need.

Thank you.