One major thing that is confusing for programmers coming to blueprint scripting is that boolean nodes and select nodes evaluate all inputs rather than only evaluating inputs that are necessary for the result (ie. short-circuiting). I didn’t see a similar post and I’m curious if other people feel the same way.
For example, I can write a valid line of C++ code like this:
if (pTarget != nullptr && pTarget->NetPriority == 5) {}
But the same thing in blueprint will crash if the target is not valid because the lower logic is evaluated by the “AND”:
The workaround involves adding a branch and a temporary variable but that doesn’t seem as clean and can’t be as optimal. Anyone agree?
With short-circuiting if the first input is false to an AND node the second input should not be evaluated. So if Target is not valid it should not query the NetPriority and crash.
Similarly if the first input is true to an OR, there is no need to evaluate the following inputs. And SELECT should only evaluate the input that was selected.
While I do agree with you that if one branch of an “And” or an “Or” satisfies (or fails) the check, the second check should not be evaluated. However, for the example you show above, there is an easy solution since you are evaluating “Is Valid”. Rather than use the function “IsValid” use this node:
I was originally thinking of a situation where I wanted to get a boolean value either to be used in a later branch or as the return value to a function. Here is what I want to do: