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.
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).
On this topic, am I crazy or does switch on enum returns the first value as default?
In the following case, when âInput Storageâ array is empty the first Enum will always play:
correct an Enum cant be empty so it will be the first/default value, this is why often people will add a âDefaultâ value at the top of the Enum list