Switch On String (I don't like it, and I know you don't either)

Hello Unreal-lites,

I do not like using switch on string, but Widget Comboboxes (afaik) only allow text. I am building a Dev Menu when selecting a level from within the Content folder and not playing through the main menu. If the developer wants something, they can press a key to bring up a series of comboboxes to request things.

I came across what appears to be a bug, but perhaps it is intended. The first selection in a combobox is None. When the combobox event named OnSelectionChanged fires, I fire an event on the playercontroller passing in the string argument that was selected. I use a Switch On String node to decide what to do. However, it appears if the Switch exec pin is labeled None, its text does NOT show up in the SwitchOnString node.

Has anyone else seen this? Not sure if I need to fill out a bug report or if it is intended. I can’t find anything stating this is intended and supposed to happen:

Capture.JPG

Not sure if it’s a bug but ‘None’ is a somewhat reserved word. Naming any exec pin ‘None’ removes the text and leaves the pin icon only - something I actively use every now and then. You can see it in macros, functions, events and so on.

Since the node is not to your liking, why not use an enumerator - in the long run they’re just so much more flexible, reliable and mesh so well with the Select node.

2 Likes

Hey @Everynone,

Enumerators are definitely the way to go, but Widget Comboboxes don’t accept enumerators (afaik).

Wait… as I’m typing this, I can create an Enumeration, and load its values into the combobox at Runtime instead of using the Designer to pre-populate :slight_smile:

You’re a genius, thanks for helping me :slight_smile:

-Erol

Hold up. Enumerators are stripped of their text in a packaged game. So if you populate your combo box from the enumerator’s values, in packaged game the combo box options will look like “enumerator_0; enumerator_1; etc.”

As a quick and dirty work-around, you could use a Select String node based on the enumerator and enter your values there.

You can use preconstruct like so:

The above example works in packaged. Perhaps you meant the enum descriptive text?

Nope. Unless there has been a change with 4.23? I just had to fix this on all my widgets.

Maybe you are not packaging as a shipping build? The actual text of an enum item is editor only for me, and I’m on 4.22.

Check this thread: BUG? - Enum text treated differently in editor and packaged project - Feedback for Unreal Engine team - Unreal Engine Forums

Yup. Win 64 package. I just tried it with 4.23.1 btw. Not going to pretend to understand well how the reflection system works, just reporting that it does, indeed, seem to work fine (on my end).

Consider giving it a try in a clean project.

edit: perhaps that’s the bug you’re referring to: Unreal Engine Issues and Bug Tracker (UE-15811)

Ditto. I’m glad to hear it’s working now. Again, I’m in an older version.

Hey @Everynone Right! Yesterday, I successfully implemented almost identical to the image you posted. I did it in Event OnInitialized because the documentation says the only event to fire once during initialization/construction is Event OnInitialized. Your thoughts gave me the rubber duck I needed. :slight_smile: