In most programming languages I’ve worked with, if you do
if (BoolA && BoolB)
and BoolA is false, BoolB doesn’t even get evaluated. That’s not the case in the Blueprint AND/OR Booelan nodes. Even if the first connected pin evaluates to false on an AND node, the others are evaluated. The same goes for an OR node, evaluating all pins even if the first is true.
Steps to reproduce:
- Create Actor Blueprint
- Create Array variable of any type and leave it’s default with 0 elements.
- On Actor’s Tick function create a graphic like the image below
-
Watch Output Log window: even though the first pin returns false, it still tries to evaluate the second one, throwing a warning like
LogScriptCore:Warning: Attempted to get an item from array [VarName] out of bounds [0/0]!
Even disconnecting the second Branch it still throws the warning, as the second Branch was already not being executed.
I’m complaining because the only way to avoid these warnings is creating another Branch and separating the evaluations putting in the first the Index Validation and, in the second, the Get Index. That gets cumbersome really fast. Also, knowing all of the pins are evaluated rises a performance concern where I can no longer optimize by putting the most probable false node first to avoid the evaluation of the others.
I acknowledge that if I’m so concerned about performance I should be using C++, but I just wanted to point an optimization possibility for BP, as it’s so practical for prototyping =D
Let me now if it’s not possible and why, please.
Thanks, guys!