Using boolean logic nodes with IsValid

Hello everybody,

I’m used to programming in C# in Unity, and a certain behaviour of Unreal is really bugging me:

I want to check if a variable is set, and if it is, further compare its attributes.

The problem with this setup is, that it gives me a ton of errors if TestVariable is null. Apparently it doesn’t break out of the OR-node after the first condition is met.

In Unity, I often did this:

if ((variable != null) && (variable.value == x))
{
//... do stuff
}

I was expecting the boolean logic blueprint nodes to work the same way, but instead Unreal seems to always check all conditions connected to the node.

So, could somebody tell me how I can get this to work properly?
Thanks!

the problem is that youre checking if its valid, and in the same branch checking the value. if its not valid than trying to check that value will always give you that error. instead do a branch checking isValid, then from the true part of the branch make a second branch checking the value

Thanks for your answer! Using two branches does works.
I would prefer a solution without a branch though, to be able to use it in pure functions.

Yeah I don’t know why this wouldn’t work as it does in code. I guess they assumed that BP programmers wouldn’t always get the boolean order right so always check both in an OR rather than abandoning if the first returns false. Sometimes two branches isn’t a tidy solution.

Short-circuit evaluation not doing its thing in BPs.


Wouldn’t it be nice if you could False this without doing the expensive evaluation:

1 Like