# Switching On Enums With Bytes

**URL:** <https://forums.unrealengine.com/t/switching-on-enums-with-bytes/335836>\
**Category:** Platform & Builds\
**Tags:** Switch, enumeration, unreal-engine, bug-report, UE4, Blueprint, question\
**Created:** [October 19, 2015, 11:29pm UTC](https://forums.unrealengine.com/t/switching-on-enums-with-bytes/335836 "2015-10-19T23:29:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kuroodo\_Ditory](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/kuroodo_ditory/32/567661_2.png) [@Kuroodo\_Ditory](https://forums.unrealengine.com/u/Kuroodo_Ditory)\
**Post date:** [October 19, 2015, 11:29pm UTC](https://forums.unrealengine.com/t/switching-on-enums-with-bytes/335836/1 "2015-10-19T23:29:08Z")

</div>

I finally figured out an issue I was having for an hour…

Basically I have an enum called Pickup\_Enum. I am trying to get a random entry from that enum by getting a random byte between 0 and the total amount of entries in the Enum. Then I switch on that value in order to spawn a specific power up. The problem was that for some reason sometimes the enum wouldn’t switch and the execution stopped, which messed up the entire game. I originally only had one entry in the enum (temporarily), but adding a second one didn’t do anything either.

After figuring out the issue, I tried to easily replicate it.

 ![63354-1.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/8/4/f/84ff7da3be06f438991f7656d8d2457eae23b3db.png)

 ![63355-2.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/b/3/7b396cf021fc4f570b814c748da244abaa22b3c3.png)

Create an event when you press any key you’d like (I chose F). Create 2 integers (I made em Press, and Press2 just to be quick).

Increment Press2 by 1 whenever you press F. Then, perform the switch on the enum. After that, increment Press by 1 on all switch values. Then just print out the values of Press and Press2.

So while pressing F, you might notice both values incrementing at the same time. But sometimes you will notice that pressing F does nothing. Eventually when the text prints again, you will see that Press 2 will have a higher value than Press.

![63356-3.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/3/c/7/3c797aced536284174a8cd35575091de6bb5812d.png)

This issue could be that there is some sort of default value that isn’t being shown, or the problem is the way I am getting a random value.

---

<div class="post-metadata">

**Author:** ![TJ\_V](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/tj_v/32/1008648_2.png) [@TJ\_V](https://forums.unrealengine.com/u/TJ_V)\
**Post date:** [October 21, 2015, 8:31pm UTC](https://forums.unrealengine.com/t/switching-on-enums-with-bytes/335836/2 "2015-10-21T20:31:16Z")

</div>

Hi Kuroodo Ditory,

The ‘Get Num of Enties’ node is returning the value of 2. So the ‘Random Int in Range’ is getting a value of 0, 1, and 2. The Enum is only 2 long but the indexes are actually 0 and 1, so each time you get a 2, it doesn’t print.

Make this change to your blueprint and it should always return the correct numbers.

 ![63590-switchonenum.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/a/1/2/a120b81dd60ea7c9cf9f7f9c0dd4c5a682000997.png)

Let me know if that works for you.

Cheers,

TJ

---

<div class="post-metadata">

**Author:** ![Kuroodo\_Ditory](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/kuroodo_ditory/32/567661_2.png) [@Kuroodo\_Ditory](https://forums.unrealengine.com/u/Kuroodo_Ditory)\
**Post date:** [October 21, 2015, 8:55pm UTC](https://forums.unrealengine.com/t/switching-on-enums-with-bytes/335836/3 "2015-10-21T20:55:36Z")

</div>

It worked! Thanks for the info & solution.
