Help an old fart understand: Branches in Blueprints

My first question was a bit of a rambling, incoherent mess and managed to confuse the kind gentleman who answered so this is hopefully a more succinct first part in my attempt to gain a better understanding of the differences between blueprints and my experience (Java, PHP, Javascript). To wit this question pertains to branches (if statements) and their use with complex/convoluted conditions.

Given that:
this_site is an integer index defaulted to 0
voronoi_sites is an array of site objects (custom structs)
first_circle_event is an integer index defaulted to -1
circle_events is an array of circle event objects (custom structs)

If I directly convert the following condition to blueprint nodes:
if (this_site < voronoi_sites.length && (first_circle_event === -1 || voronoi_sites[this_site].y < circle_events[first_circle_event].y || (voronoi_sites[this_site].y === circle_events[first_circle_event].y && voronoi_sites[this_site].x < circle_events[first_circle_event].x)))

I get:

If first_circle_event is still at the default value of -1 I would expect the condition to pass as soon as it gets to the first_circle_event === -1 and not bother evaluating the following conditions which rely on first_circle_event being a valid index. However when I use a single branch all conditions are evaluated and warnings are thrown.

If I replace this with three sequential branches then I don’t get these warnings, all is logical but now I have three nodes each with their own paths and it’s less clear what is going on at a glance.

Am I getting this right? I’m not looking forward to updating all my branches but I don’t want to simply suppress warnings either. Is there a way to enter a conditional formula that creates a single collapsed macro node like the Math Expression Node? Any other approaches that may be attractive to a very lazy person? Or should I just stop being precious, blow the cobwebs off my brain and get with the program?

Specifically which warnings do you get when using the single-switch?

Thanks for the response, I get multiple instances of:
LogScript: Warning: Script Msg: Attempted to access index -1 from array ‘circle events’ of length 0 in ‘/Game/Globe.Globe_C’ ie trying to request an out-of-range array index.

To my current understanding of how blueprint works:

When the execute path hits the branch, every node and sub-node that connects to that boolean input is evaluated.

So while you expect First_Circle_Event == -1 to be true, and the execute to move to the next node beyond the brach, that is not the case as every other node connected to the OR-node is also evaluated. So in that same instance where First_Circle_Event == -1, the blueprint will at the same time evaluate Get[-1] from CircleEventsArray which is causing you that error.

By changing your branches to the Treble-switch setup, at each branch you will evaluate the connected sub-nodes, meaning you will never try to get[-1] from the array in the same instance where First_Circle_Event is equal to -1.

This is simply how Blueprints functions, so I’m not sure if it helps solve your problem but at least I hope it helps you understand the root of your issue.

Thanks, this was the crucial missing piece of information. See my answer for details.

Thanks for confirming that, I had hoped for some nifty trick or workaround as I have even more complex conditions with multiple potentially unset indexes in other places. At the same time I feared the outcome would be the “stop being precious” option, if nobody else can suggest any effort saving techniques soon I’ll accept this, bite the bullet and redo all the affected conditions. Cheers :slight_smile:

Unfortunately I believe this will have to be redone as Weibye stated the branch will evaluate ALL conditions at once. Which means your entire tree will be evaluated at the first branch because they are all interdependent in blueprints.