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.
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.
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.
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.
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).