x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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: alt text

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. alt text

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?

Product Version: UE 4.20
Tags:
single-switch.jpg (205.5 kB)
trebble-switch.jpg (212.0 kB)
more ▼

asked Jan 23 '19 at 10:25 AM in Blueprint Scripting

avatar image

renwerx
8 1 1

avatar image Weibye Jan 23 '19 at 10:56 AM

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

avatar image renwerx Jan 23 '19 at 11:26 AM

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.

avatar image Weibye Jan 23 '19 at 11:47 AM

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

(comments are locked)
10|2000 characters needed characters left

1 answer: sort voted first

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. alt text

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.

capture.png (333.8 kB)
more ▼

answered Jan 23 '19 at 11:46 AM

avatar image

Weibye
275 1 7 5

avatar image renwerx Jan 23 '19 at 01:18 PM

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 :)

avatar image Nebula Games Inc Jan 23 '19 at 02:14 PM

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.

(comments are locked)
10|2000 characters needed characters left
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question