i've noticed a flaw in AND logic gate in blueprints, and proposing an optimisation.
in C++ and raw logics, boolean "&&" (AND) operator, if the first condition (out of 2 or more) is false, the second condition doesn't get checked, because the result is determined as FALSE already.
Unreal Blueprints don't follow this, and
here's why it is bad:
also:
i assume the same issue occurs with "OR" gate, in which the first condition "TRUEthness" is enough for success. this can be a good player in optimization as well.
thanks for reading.
solution:
please modify AND and OR blueprint nodes to follow C++ optimization tactic above. complexity=VERY EASY
[details]:
bool UKismetMathLibrary::BooleanAND(bool A, bool B)
{
return A && B;
}
nativized build translates blueprint "AND" to the above, which is a regular C++ way (follows the optimization unlike the blueprint). it can cause very serious and hard-to-detect bugs if any of the later conditions (after a FALSE one) contains an impure function ("impure" means it alters some variables states on the run, it other words it is Read+Write), this function will be shot in blueprint but ignored in C++. a direct way to desync hell.
[/details]
in C++ and raw logics, boolean "&&" (AND) operator, if the first condition (out of 2 or more) is false, the second condition doesn't get checked, because the result is determined as FALSE already.
Unreal Blueprints don't follow this, and
here's why it is bad:
- additional steps get interpreted and checked (very likely calculated in a long process), which can be simply ignored, to make the AND node so much faster.
- leaves a window for runtime error; imagine this case: {hasKnife AND knife->isScary} null reference will occure, even though the execution will be cut off anyway because of first condition state:FALSE.
- ruined logic compatibility with the native C++, in which the previous section example is a natural expression type which programmers use worldwide.
- [4.15+][VERY SERIOUS] logical flow difference between "nativized build" and "not-nativized build". see [details] at the end of the post for more.
also:
i assume the same issue occurs with "OR" gate, in which the first condition "TRUEthness" is enough for success. this can be a good player in optimization as well.
thanks for reading.
solution:
please modify AND and OR blueprint nodes to follow C++ optimization tactic above. complexity=VERY EASY
[details]:
bool UKismetMathLibrary::BooleanAND(bool A, bool B)
{
return A && B;
}
nativized build translates blueprint "AND" to the above, which is a regular C++ way (follows the optimization unlike the blueprint). it can cause very serious and hard-to-detect bugs if any of the later conditions (after a FALSE one) contains an impure function ("impure" means it alters some variables states on the run, it other words it is Read+Write), this function will be shot in blueprint but ignored in C++. a direct way to desync hell.
[/details]
Comment