any way to get a string to an enum

hi

is there any way to get or cast a string to an enumerator value

or will i need to test the string against each enumerator value in the enumerator set

thanks

1 Like

You can probably do it if the string is just 0, 1, 3… etc. Otherwise you’ll need to use a switch node :slight_smile:

1 Like

Look into game play tags, they are kind of advanced enums.

With enums there is one problem they are kind of compiler editor thing. Really they are just byte/integer but compiler remembers that enum_0 is for eg WALK, and enum_1 is RUN. In C++ this is strict, and makes enums from C++ just messed up on Blueprints side. Blueprints are not as strict, but enums still are messy.

So it is better to use gameplay tags, they have more functionality in blueprints.

ps.
You can also see if NAME and switch on name solves your needs. Names are more strict strings.

1 Like

Perhaps that’s the real issue. Why use strings for comparison - isn’t it one of the most inefficient methods? Perhaps you could use a Name | Enum association map? Or just use enums everywhere.


You might be making a crossword game for all we know so string comparison might as well be the very best way. :person_shrugging:

1 Like

it is a case of having an enum entry in an enum list
and dereferencing that for a button name (enum list > enum > string)

and then having to move back to enum entry nr in enum list afterwards
maybe i should simply save the original enum better
seeing there is no real easy way to move from string to enum as there is to move from enum to string
at the moment i am for each enum and testing the enum string against the string

other thing is for each enum also do not have a break like other loops

Again, I sense the issue is elsewhere entirely. Why use a string + loop in the first place. Enumerator Set / Map look-ups are instantaneous by comparison and not prone to typos:

For example, the last one would remove a unique soft object reference from a list, and we don’t care if the list is 10 or 10 million entries long since we do not need to iterate over anything. No need to Break because we’re not even moving.


Not sure if this is applicable since I have no clue what you’re up to. I just sense that you’ve pigeonholed yourself into using a tool / method that is not suitable for the task at hand.

If you’re doing this but the project is not a word salad puzzle thing:

I’d rethink the approach. Good luck!

1 Like

I’m guessing maybe the OP is maybe getting the data from an external source like a json file from a server. Then you might need to convert a string to an enum.

But I’m just guessing, that’s the only time this sort of situation would occur. If it’s just in game then that’s bad practice and should be limited to enums period.

2 Likes

That’s more than fair. I’ve seen folk import data from unorthodox sources; but then you’d parse it and assemble it once, into something the engine can handle more gracefully from then on.


Whenever I look at this node:

I cannot shake this feeling of laboriously running a finger under every letter of every word I read in a book. :innocent:

2 Likes

lol
great response

its an enumerator list because its a list and enumerators work best for lists for me
if i leave it int i always forget what option 1, 2, 3… refer to later on
in that sense enumerator acts 2 in one. it delineates and describes. i have the list options outlined with a name
some of the enumerator list entries must end on a widget interface (button text etc)
and its easy to go enum to string for that purpose

later on at some / whatever point i must again go back to the enum list to know which entry has been selected

it would have been great if there were an easy way to go sting to enum. 1. clearly there is not. 2. it is not that far to go te perceive

so i guess i better store the user interface corresponding values adjacently so streamline this

also switching between enum and int is not too difficult and i sometimes do that

and i have now found a way to break a for each enum. i simply call it in a function and use a return node at the end to break the loop by a return

so maybe you are right. a switch would be more efficient than an corresponding entry search / comparison

and there is enough reason to keep to enums instead of switching over to string (list) completely