Keyed Enums

Is it possible to make a Keyed Enum for use in Blueprints?

I’m probably overthinking this but I’m still learning what is doable in Blueprints, and so far It seems better to be right than having to refactor after a mistaken choice.

in C or other languages, I’d probably do something like this:

enum Option {option1 = 0, option2 = 16, option3 = 32, option4 = 80, option5 = 81}

I’m receiving a mode flag from an external device, that service gives me an 8-bit int and I use it to choose an execution path. I’d like to keep using Enums since it makes it simpler to maintain.

I have an Enum that contains all of the options

image

but their values don’t start at 0 and have arbitrary gaps in them.

So to get around this I made a Map of My Enum and just set the values:

Then I can find the Value in the map and that gives me the enum from.

While this works I need to maintain the list of options and their mapping separately, and this seems like a bad idea.

So then I had the idea (Good or bad) to try using Data Tables.

So I made a struct from the enum:
image

Then a DataTable from that struct putting the Int Values in the row name (again probably not a good idea)
image

Then I can Get the row based on the (converted x2) Incoming Int:

While this seemed almost simpler to follow and looked promising it seemed even more convoluted to find the row based on the received int and I still have to maintain the enum and DataTable Separately.

I even tried just switching on the Incoming int, While this is the simplest of all the options I have tried… please no!

So my question is; is it just simpler to build the map or is there some other way to build a keyed enum without having to pull out the C++?

I’m not against using C++, just haven’t done it yet, and not sure if that will cause other issues if I try to bring that back into blueprints.

Do you have to use “Option1”, “Option2” … and so on?

Hey @Shunitzo thanks for the reply.

The top one was one that I tried, but Switch on a cast String is an interesting idea.

I’m really back and forth on this.