Help with "if, else if, else" blueprint macro

I’m trying to make a blueprint macro that combines multiple branches into an “if, else if, else if, … else” format. Easy enough, but I was hoping to make its length dynamic by having the little “Add pin (+)” option in it much the same way sequence or switch nodes work.

If this requires coding that’s fine. I just want to know if it’s possible, and how to do it. My google-fu has turned up nothing.

Bumper cars

Hi, Have you looked into using the Switch on Int node ? It’s a flow node that takes in an integer (you decide how many cases you want by the Add Pin (+) option you requested), and it diverts the program flow to the output flow node that matches your Int input… Other switch nodes are also available, and might suit your program better than the int one…

Even better, Switch on Enum. :slight_smile:

Also, consider the OR node. It helped me clean up quite a few branches by using them.

I’ve used many of these methods and they work fine, but what i’m hoping to achieve is something simple and direct that I can add to the macro library.

The end goal is to make a single macro with as long a chain of branches as desired, starting with 2, and being expanded with the [Add Pin +] button.

If this is impossible to make with the current tools hopefully the UE devs could implement something like this in the future.

Example:

6719-ifelse2.png

If procedural node creation is possible it is somewhere in C++. I would suggest reposting this question in that answerhub for the best results.

I am curious though, what kind of mechanic are you thinking about that would need such a macro? You could probably emulate the same kind of thing with Arrays. X Happens, then Array element is generated that runs a Switch to Y branches.

Essentially your basic branch setup will reach some fundamental limit of complexity, so that is how big your Enum would be. Then you procedurally generate the Array elements to choose between them. Your array could be an arbitrary length and accomplish the same thing as your proposed Branch idea.

You’d use this any time you’d need an if chain. So:

if (numChar < minNum)
    { // too few}
else if (numChar < lowNum)
    { // comfortable}
else if (numChar < maxNum)
    { //crowded}
else
    //too many

In blueprint, this would require 3 branch nodes. The macro would reduce this to just one. Even just combining two nodes into one would reduce clutter, and that’s exactly what macros are for.

As for using arrays and switches, that’s fine as long as I plan to check the array variables enough times to make the hassle of setting it up worthwhile. I’d also only be able to use that setup in that specific instance. Remember, this would be in a macro library, so any project that has access to that library would be able to use this, pick the number of conditions, plug them in, and be good to go in seconds.

2 Likes

Oh I see.

I guess that would almost be like a Switch on Boolean.

pretty much

Sorry for digging the old post.
I think the below code plugin meet your requirement.