Waiting for to finish before continuing foreach loop?
I have a headache trying to figure this out.
The basic problem is this:
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.
asked Jan 20 '17 at 12:21 PM in Blueprint Scripting
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.
answered Jan 20 '17 at 12:45 PM
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.
answered Jan 20 '17 at 02:01 PM
Hei @Drunkenvalley, it is correct that a
In blueprints that looks something like:
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.
answered Jan 20 '17 at 02:30 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here