The best way to get combination of many booleans?

I need 4 booleans showing each different outputs for every combination, which will be total of 16 cases(0000, 0001, 0010, … , 1111).
The simplest way to do this would be just lining up a bunch of branches like this.

I would need more than 10 actors having this custom event being called every second. However, calling more than 40 branches every second doesn’t look good. I’ve searched alternatives for many branches on the internet but couldn’t find a clear and short way to determine the combination of many booleans.

How can I get the combination of 4 booleans using shorter than 4 steps?

There are probably ways to simplify this, but without seeing your actual implementation there aren’t any obvious simplifications.

Remember that branches are just if statements- they’re the most basic of basic things you can do. It won’t have a large performance impact to have even 100 actors running that. Of course, assuming none of the conditionals are complex pure functions.

If you send images of your implementation of this function or the problem you’d plan on using it to solve I could probably help more.

Further to what @rokenrock says, maybe describe the overall concept. How did you end up with so many bools?

Seems a logic gate combination based on AND, OR, NOT, XOR would probably be the fastest solution.
You would have to cook down the paths to specific fixed gates.

Thank you for your reply. I wrote a quite long description trying to explain how I got stuck here.


The actor itself is in the thick red circle. It is a fighter jet.
There are 4 box collisions(marked by green lines), forming a cross shape with the actor in the middle. I’m trying to make the actor fly by itself, avoiding the landscape by detecting it using these box collisions.

4 booleans for 4 collision boxes, and these help the decision where to turn while flying.
For example, if the collision box on the bottom is overlapping with landscape, the actor would pull up to avoid colliding. The booleans are used to check whether there are any landscape overlapping every second.


This is the actor’s tick event. ‘Update Position’ makes the fighter jet fly smoothly, ‘Path Finder’ makes decision where should the fighter jet go to. ‘Manage Targets’ helps to decide which actor should the fighter jet shoot down.

All the problems coming from the 4 booleans and additional booleans are in the ‘Path Finder’.

As you can see, currently it is consisted of several branches ordered by priority, each telling to do something if the branch was true. Each booleans’ values are determined in other places like overlap events or interfaces, custom events. The 4 booleans were intended to be here(Path Finder) but I noticed that there would be endless branches if I keep adding up functions.
I decided to replace all the branches with a single ‘switch on int’. All of the branches will be called by a custom event every second instead of every tick.
I don’t know how much will the performance be enhanced but I just made a vague prediction that a single switch will be better than 10 branches.

t5
This is the last part of ‘begin play’ event.


This is the ‘PathDecision’ custom event which will be called by begin play event.
The issue about many branches stuck me here again.

While I’m not sure how to simplify the branches in blueprints, this is absolutely the best case scenario to use a behavior tree.

You mean using the behavior tree for the switch integer decision? or the entire code(updating position, managing targets and destinations) in the tick event?

I mean the entire code. Though it might take some work, behavior trees were literally created for this type of behavior.

I had seen a few behavior tree tutorial videos before but all of them were just using AI perception, x and y axis in order to use the navmesh. My project requires all x,y,z axis and big collisions to inflict damage or detect other actors so I couldn’t understand the whole thing about behavior trees and that made me give up soon.
Is there anything that I should leave instead of converting into behavior tree(such as collision overlap events, any damage events, tick events to move)? or Is it impossible to use both the behavior tree and blueprint nodes in the actor? I’m already kind of stuck from the beginning line

It definitely possible to use both behavior trees and blueprints. In fact, it’s recommended. Like using both blueprint and c++, not just one or the other.

I would recommend using the blueprint to fill in the values of the behavior tree’s blackboard. So the blueprint would set values like IsExhausted and IsMissileIncoming in the blackboard.
The behavior tree itself would then act as the logic (branch nodes) and would lead to custom tasks that execute your functions (like add actor local rotation).

What you should do is watch a comprehensive guide on behavior trees and blackboards. Behavior trees are extremely versatile, so even if the tutorial doesn’t go over your exact use case, you can morph it. Make sure it covers tasks.

Thank you for your replies. I’ll try the behavior tree again