IsValid node and variable checks

Hi there!

I have a macro where I check the validity and type of a weapon actor variable.

In programming, if the first variable in an AND is false, the whole AND is automatically considered false and the other variables don’t get checked. So I thought this would be a valid way to go:

But when my Active Weapon variable is invalid, checking the weapon type like this causes an error.

Any advice?

Thanks and cheers!

1 Like

I think it is because of the lack of execution wires. I tried a similar approach with the select node and no execution wires, but it didn’t work out.

So I’d rather use IsValid? node to first, with the execution wire, and then check for the enum if the result was valid.

The Blueprint logical functions like AND needs to pass on all the parameters, which prevents it from doing a short-circuit like in C++.

I guess the select node is somewhat similar, because it didn’t work with it, either.

Edit: actually yes, of course that is true, because that’s how UFUNCTIONS() work…

The Select node has a rather complicated setup afaik. I would not trust it to never evaluate all the parameters but sometimes it works fine.

As GarnerP57 said; there’s a good read in the forums about the issue and it’s nicely summarised in this [post][1].


From my personal experience, the Select node evaluates everything - never trust it. Feeding it a null reference will always throw an error.


So I’d rather use IsValid? node to
first, with the execution wire, and
then check for the enum if the result
was valid.

Saves a click or two every now and then:

294804-untitled.png

2 Likes

All the inputs to UFUNCTIONS() get passed in as parameters so of course they need to be valid, I just never thought about it for some reason despite having used the macro a plenty to make my own nodes… although the input parameters for select node are not as standard as on other nodes, they are still input parameters.

Personally I prefer the visual feedback with a grey top bar and the ? symbol on top of the is valid node, validated get node makes the graph less readable imho. The grey top bar in particular will be consistent with all gates, branches and sequences and such which result in branching logic.

That said it’s another way to do it, though it’d be nice if validated get nodes also had some kind of visual highlighting that would make it easier to visualize the graph.

As GarnerP57 already mentioned, there seems to be no short-circuiting evaluation. It seems that Blueprint evaluates all of the nodes as soon as they are needed for your macros And-Node.

If you really want to avoid having execution wires I’d suggest to convert the macro to a function that is both pure and const, as seen in the attached image. In the picture I have also included the (selected) resulting node