Why is there no Default pin on "Switch on Enum" node?

Switch on Int has a default pin.

Switch on String has a default pin.

Switch on Enum does NOT have a default pin.

What am I missing here? This seems like pretty basic functionality to omit.
My use case is an enum with a dozen values, used in multiple blueprints. Each of those blueprints reacts to 2/3 values positively, and the rest negatively. Without a default case I have to hook up all 8/9 negative cases manually in each blueprint, and when I add a new enum to the list I have to go through EVERY blueprint that references it and hook the new value up to the negative case.

[EDIT]
Here’s how I’m working around it for now, reacting to 6 out of 12 cases and allowing the rest to drop through. Not very elegant, is it?

It doesn’t make sense for a ‘switch on enum’ to have a default pin; what would the default be? An enum is always a specific value.

The whole point of an enum is that it is a specific enumerated value. If you need a default value in your enum, then literally just make a “default” value at 0, or whatever works for you. An entry which is used solely as the pseudo-default.

The only reason the default pin exist for ‘switch on string’ or ‘switch on int’ etc., is because there is an infinite amount of values that it could receive, so it needs the default pin to account for those inputs that aren’t accounted for (to phrase it vaguely).

An enum, by it’s design, doesn’t have this problem, and so it doesn’t need or benefit from a default pin. You are probably using them in a weird or incorrect way if you think that you need that.

No - in a C/C++ switch statement the Default state fires for any enum that is not explicitly handled. This is useful for readability (avoiding long lists of case declarations) and for future-proofing code (so that it still works if new cases are added). I would like the blueprint to behave the same way.

2 Likes

That’s true. But I don’t think many developers would use the “default:” fallback as an integral part of their design, if htey are using enums. In my opinion, that would mostly only be used for handling errors.
edit: But I see what you mean, when compared to C++ this does work different in Blueprints currently.

You need to drag off the Switch from your enum (For Blueprint only)

224522-enum.png

Yeah, sorry I misunderstood your question. Personally, I use macros to handle some enum. A quick example :

Or I put some parameters in the macro in case I want to change my selection

224524-01.png

No, I can see the node. The problem is that the node only provides the 9 outputs but no general-purpose default.

I guess, if one could modify the switch node to include certain cases, and everything else just goes to ‘default’, that would be useful.

Yep, this is a good solution. Was being a bit shortsighted above.

Thanks, will check out what I can do with macros…

Yeah, thanks Jin_VE. I’ll stick with my long form (but slightly more readable) hack but this could work better for some cases.

I know what you’re saying. It would be nice if you could add output execution pins for the enum entries you want and have a default pin for the ones that aren’t listed. I can’t answer why that isn’t available but I can make a suggestion in two parts:

First, if you want a feature added, there’s a section in the forum for that. I’d ask a little more nicely though because there are a lot of fixes/features already in the pipeline. If you post a suggestion, link it here. I’ll endorse it.

Second, in the meantime, you can drag off your enum and choose “To Int”. Then pass that into a “Switch on Int” (see below). You lose the names but you get the default pin and time saved.

And I suppose you could implement this functionality yourself. If it works well you could even submit it for inclusion in the next UE4 update.

224525-switchonint.png

The most elegant solution I can think of

That is neat, although doesn’t work for me because my “interesting” enums are scattered, not sequential. Thanks for the idea though!

why are you using a switch when you only want to check if your Enum is in 2/3 of all possible states?

when you Enum is not one of the checked values it will always on of the other, there no need to check them all

Because

a) I naively hoped that the blueprint node would match the C++ behaviour

b) What you’ve suggested there is nicer than my layout, but still 5 nodes instead of 1

Bit of a solution: use a switch on GameplayTag.
It has a default and you can pick wich cases to treat.
Define a category as such “Enums.Animals.Elephant”
Added benefit: can referenced in code and expanded in BP (enums cant do that).

Sorry for necro, may this help future visitors.

2 Likes