# Integer to enum(byte) with strange casting result

**URL:** <https://forums.unrealengine.com/t/integer-to-enum-byte-with-strange-casting-result/330589>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine\
**Created:** [September 1, 2015, 9:26am UTC](https://forums.unrealengine.com/t/integer-to-enum-byte-with-strange-casting-result/330589 "2015-09-01T09:26:40Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![CrispyVitamin](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@CrispyVitamin](https://forums.unrealengine.com/u/CrispyVitamin)\
**Post date:** [September 1, 2015, 9:26am UTC](https://forums.unrealengine.com/t/integer-to-enum-byte-with-strange-casting-result/330589/1 "2015-09-01T09:26:40Z")

</div>

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](https://d3kjluh73b9h9o.cloudfront.net/original/4X/5/8/3/5831ca03d56df3ca675baed5622d307cf823efab.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](https://d3kjluh73b9h9o.cloudfront.net/original/4X/4/e/f/4eff04145c0c8d82edc717cf658f7d03ab2b3a25.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](https://d3kjluh73b9h9o.cloudfront.net/original/4X/8/1/9/819fdda3aba492d5b8c872d9d78e4d4cce20379c.png)

My enum is like this:

![56594-enum.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/a/e/8/ae8550f90386495a59720de10fe9ba80b0994344.png)

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

 ![56591-bp.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/3/1/1/3116f65f5f0e4208bb1e485ce7616a99ae9ba24c.png)

Can you help me with this issue? Thanks. 🙂

---

<div class="post-metadata">

**Author:** ![CrispyVitamin](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@CrispyVitamin](https://forums.unrealengine.com/u/CrispyVitamin)\
**Post date:** [September 1, 2015, 9:38am UTC](https://forums.unrealengine.com/t/integer-to-enum-byte-with-strange-casting-result/330589/2 "2015-09-01T09:38:23Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![CrispyVitamin](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@CrispyVitamin](https://forums.unrealengine.com/u/CrispyVitamin)\
**Post date:** [September 1, 2015, 9:46am UTC](https://forums.unrealengine.com/t/integer-to-enum-byte-with-strange-casting-result/330589/3 "2015-09-01T09:46:56Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Iohoilpotere](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Iohoilpotere](https://forums.unrealengine.com/u/Iohoilpotere)\
**Post date:** [September 1, 2015, 10:16am UTC](https://forums.unrealengine.com/t/integer-to-enum-byte-with-strange-casting-result/330589/4 "2015-09-01T10:16:35Z")

</div>

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?

 ![56602-enumbug.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/e/4/8/e488424250f4ee01a8ab349ff69152ec4402d5fa.jpeg)

(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.

---

<div class="post-metadata">

**Author:** ![CrispyVitamin](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@CrispyVitamin](https://forums.unrealengine.com/u/CrispyVitamin)\
**Post date:** [September 1, 2015, 11:42am UTC](https://forums.unrealengine.com/t/integer-to-enum-byte-with-strange-casting-result/330589/5 "2015-09-01T11:42:41Z")

</div>

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](https://d3kjluh73b9h9o.cloudfront.net/original/4X/e/8/0/e809ba5c03a8ab44c0099630920acffa67bbebc4.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](https://d3kjluh73b9h9o.cloudfront.net/original/4X/1/6/5/165377f67d8a22f32f5e5809c1648f4fd1322667.png)

My bp graph:

 ![56620-bp.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/f/6/2/f620da5bf38863bbc31310ed530e64a2205c735c.png)

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

---

<div class="post-metadata">

**Author:** ![CrispyVitamin](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@CrispyVitamin](https://forums.unrealengine.com/u/CrispyVitamin)\
**Post date:** [September 1, 2015, 12:01pm UTC](https://forums.unrealengine.com/t/integer-to-enum-byte-with-strange-casting-result/330589/6 "2015-09-01T12:01:17Z")

</div>

Add a new set of pics for more clear comparison.

![56626-result2.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/8/1/6/81603897f5ea0286f812c041e453d04e4557d3b9.png)

![56627-playdetail2.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/8/b/0/8b0f0eaeaa27d1803c7952525a3d0d6840ef9cbc.png)

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

Enum order:

![56628-enum+order.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/4/5/6/45610b8b04b5b93a235ae6bb88c15fa41393ee1c.png)

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_33800a51](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_33800a51](https://forums.unrealengine.com/u/anonymous_user_33800a51)\
**Post date:** [September 1, 2015, 5:03pm UTC](https://forums.unrealengine.com/t/integer-to-enum-byte-with-strange-casting-result/330589/7 "2015-09-01T17:03:37Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![CrispyVitamin](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@CrispyVitamin](https://forums.unrealengine.com/u/CrispyVitamin)\
**Post date:** [September 1, 2015, 5:52pm UTC](https://forums.unrealengine.com/t/integer-to-enum-byte-with-strange-casting-result/330589/8 "2015-09-01T17:52:11Z")

</div>

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](https://www.dropbox.com/s/px5ob13kv0pasm3/BlankEnumTest.7z)

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

 ![56681-2015-09-02_015019.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/d/3/0/d308f8dfdf51837ebfe43b91d69a0359a1708357.jpeg)

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_33800a51](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_33800a51](https://forums.unrealengine.com/u/anonymous_user_33800a51)\
**Post date:** [September 1, 2015, 10:02pm UTC](https://forums.unrealengine.com/t/integer-to-enum-byte-with-strange-casting-result/330589/9 "2015-09-01T22:02:57Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![jtsmith](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@jtsmith](https://forums.unrealengine.com/u/jtsmith)\
**Post date:** [September 2, 2015, 1:06am UTC](https://forums.unrealengine.com/t/integer-to-enum-byte-with-strange-casting-result/330589/10 "2015-09-02T01:06:22Z")

</div>

@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.

---

<div class="post-metadata">

**Author:** ![dreampunchboy](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@dreampunchboy](https://forums.unrealengine.com/u/dreampunchboy)\
**Post date:** [September 2, 2015, 1:16pm UTC](https://forums.unrealengine.com/t/integer-to-enum-byte-with-strange-casting-result/330589/11 "2015-09-02T13:16:58Z")

</div>

Is there any way to track progress on a bug?

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_33800a51](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_33800a51](https://forums.unrealengine.com/u/anonymous_user_33800a51)\
**Post date:** [September 2, 2015, 2:10pm UTC](https://forums.unrealengine.com/t/integer-to-enum-byte-with-strange-casting-result/330589/12 "2015-09-02T14:10:56Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![dreampunchboy](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@dreampunchboy](https://forums.unrealengine.com/u/dreampunchboy)\
**Post date:** [September 2, 2015, 2:14pm UTC](https://forums.unrealengine.com/t/integer-to-enum-byte-with-strange-casting-result/330589/13 "2015-09-02T14:14:49Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_33800a51](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_33800a51](https://forums.unrealengine.com/u/anonymous_user_33800a51)\
**Post date:** [September 2, 2015, 2:21pm UTC](https://forums.unrealengine.com/t/integer-to-enum-byte-with-strange-casting-result/330589/14 "2015-09-02T14:21:12Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![dreampunchboy](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@dreampunchboy](https://forums.unrealengine.com/u/dreampunchboy)\
**Post date:** [September 2, 2015, 2:25pm UTC](https://forums.unrealengine.com/t/integer-to-enum-byte-with-strange-casting-result/330589/15 "2015-09-02T14:25:09Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![CrispyVitamin](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@CrispyVitamin](https://forums.unrealengine.com/u/CrispyVitamin)\
**Post date:** [September 2, 2015, 3:26pm UTC](https://forums.unrealengine.com/t/integer-to-enum-byte-with-strange-casting-result/330589/16 "2015-09-02T15:26:02Z")

</div>

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. 🙂

Also, here’s my updated test project if you need: [Dropbox - BlankEnumTestV2.zip - Simplify your life](https://www.dropbox.com/s/9z9lve9b8q6u94f/BlankEnumTestV2.?dl=0)

And some screenshots:

 ![56818-bptest2.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/0/4/5/0455489030385370769ad70dc4861ba39257e0f8.png)

 ![56819-bptest3.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/4/9/5/495936c09fe23a09126e8d723f5a4e42b421717c.png)

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

![56820-test2-3result.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/8/3/c/83c6740e8e4c5d7d2ca744259a7206fef21ef095.png)

---

<div class="post-metadata">

**Author:** ![CrispyVitamin](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@CrispyVitamin](https://forums.unrealengine.com/u/CrispyVitamin)\
**Post date:** [September 2, 2015, 3:34pm UTC](https://forums.unrealengine.com/t/integer-to-enum-byte-with-strange-casting-result/330589/17 "2015-09-02T15:34:35Z")

</div>

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

Have a look if you need.

 ![56832-workaround.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/0/2/f/02f98063718a8d369d9628c514b074683a54d2bb.png)

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_33800a51](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_33800a51](https://forums.unrealengine.com/u/anonymous_user_33800a51)\
**Post date:** [September 2, 2015, 3:36pm UTC](https://forums.unrealengine.com/t/integer-to-enum-byte-with-strange-casting-result/330589/18 "2015-09-02T15:36:49Z")

</div>

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).

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_33800a51](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_33800a51](https://forums.unrealengine.com/u/anonymous_user_33800a51)\
**Post date:** [September 2, 2015, 3:38pm UTC](https://forums.unrealengine.com/t/integer-to-enum-byte-with-strange-casting-result/330589/19 "2015-09-02T15:38:50Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![dreampunchboy](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@dreampunchboy](https://forums.unrealengine.com/u/dreampunchboy)\
**Post date:** [September 2, 2015, 5:08pm UTC](https://forums.unrealengine.com/t/integer-to-enum-byte-with-strange-casting-result/330589/20 "2015-09-02T17:08:20Z")

</div>

Thank you.

[Next page](https://forums.unrealengine.com/t/integer-to-enum-byte-with-strange-casting-result/330589.md?page=2)
