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"

Waiting for to finish before continuing foreach loop?

I have a headache trying to figure this out.

The basic problem is this:

  1. The ForEachLoop is given an array with two items.

  2. It processes index 0 to the end. The end node is an 'AI Move To'

  3. Without waiting for the previous 'AI Move To' to finish on success it moves to index 1

  4. It processes index 1 to the end. The end node is an 'AI Move To'

  5. The 'AI Move To' at the end of index 0 is aborted

  6. The 'AI Move To' at the end of index 1 continues

So what I am trying to accomplish is to make it wait until AI Move To has succeeded (ie reached destionation), and I can't seem to figure out how to do so.

Product Version: UE 4.14
more ▼

asked Jan 20 '17 at 12:21 PM in Blueprint Scripting

avatar image

356 13 21 46

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

3 answers: sort voted first

So what I wound up doing is go away from using For Each Loop, and instead utilize my entity's tick. In there I have a "Busy" toggle.

When not busy, if I still have items in my array I will toggle busy to on and process the first item in my array. On completion I toggle busy off again, and I am able to process the next item in the next tick.

I'll leave this question up for a little longer to see if anyone else have alternative suggestions.

more ▼

answered Jan 20 '17 at 12:45 PM

avatar image

356 13 21 46

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

I'm don't have unreal on this computer, but I don't remember For Each Loop ever skipping over anything before going to the next variable in the array.

Perhaps there's a more clever workaround, but you could just put a delay node after AI Move To if you know how long it'll take for it to complete. If each AI Move To is different, then perhaps you just need another variable (or another array of integers) that stores how long the movement will take, then feed it to the delay node.

more ▼

answered Jan 20 '17 at 02:01 PM

avatar image

26 1 3 7

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

Hei @Drunkenvalley, it is correct that a ForEachLoop does not wait until the AI Move To has completed. This is because AI Move To is asynchronous, which you can tell from the clock symbol. You probably do not need to resort to the tick function with a "busy" toggle. Instead you could have an array of places to go to, possibly a copy of what you already have, and do the following:

  1. Check if the array is empty, if so you are done. If not, go to (2)

  2. Take the first element from the array and AI Move To that destination

  3. On Success, which triggers happens async, the flow continues:

  4. Remove the first element, because that is where the AI should be now

  5. Repeat starting from (1)

In blueprints that looks something like: alt text

Keep in mind that the array of destinations is modified, it only has the destinations that still need to be visited. The array can be updated while the AI moves from one place to another, just never modify the first element and it should work just fine. It might be this isn't useful for you, but you could use a similar asynchronous cycle without removing elements. In that case you just want to keep track of the current index, starting from 0 and increasing where I now removed an element. Then your "Are we done"-check should just check whether the index is equal to the length of the array.

Disclaimer, unfortunately I can't really test this solution right now, but it should work.

more ▼

answered Jan 20 '17 at 02:30 PM

avatar image

520 9 83 49

(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