Switching On Enums With Bytes

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.

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

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.

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.

Let me know if that works for you.

Cheers,

TJ

It worked! Thanks for the info & solution.