ForEach Loop Only Fires Once

Hi,

I have a blueprint that I use at the intersection of my various levels within my map to load and unload levels.

This way I can have just the levels in memory needed to support the current location of the player.

My script section looks like this

This all works great if the level intersection only needs to load and unload a single level, but if I have more than one level in my array for loading or unloading, only the first element in the array is processed, am I doing something wrong?

The arrays are of type Name and contain the level names.

Thanks in advance

It might be a timing issue from calling “Load Stream Level” within the loop before the previous call has finished.

The tooltip of “Load Stream Level” states it has no effect if called before it’s done.

20816-loadstreamlevel.png

Try to delay the execution of the loop until the “Completed” of the “Load Stream Level” fires.

Yes that is the reason … unfortunately none of the built in loops allow a wait until last loop execution finishes as far as I can tell so had to build my own

Thanks very much! :o)

I guess you can do it similar to this example. I took your variables names for easier understanding.

To get the Complete into the for loop i just made my own for loop. So i used a Get Node for the Array and a selfmade index. Everytime the Load/Unload Steam Level node is completed, i increment the index by 1 and check if it’s still lower than the length of the array. If yes, we load the next level etc. If no, we set index back to 0 and start with the Unload Stream Level node. Same here, if completed, increment index, check, repeat or finish.

Also set the index to 0 before starting with everything. You could also do it before the Switch to have one less “Set Index” node. But i made this fast to get you started :smiley:

http://puu.sh/cN1ZF/21e3748194.jpg

http://puu.sh/cN1ZF/21e3748194.jpg

You may want to check if the Level Load List is not 0, because this setup works only if you have at least 1 Level Name in that array. If it’s empty he will try to get index 0 which isn’t available and throw an error.

Thanks for that … I ended up doing a similar manual for loop using loop index and branch condition

Another idea to make it wait, haven’t tried it yet:

Add something like an arbitrary “Set” to a variable, or some similar “NOP” action, and connect it to the “Completed” node of the “Load Stream Level”.

IMO the loop should wait for that last action before running the next itaration, and that action is only fired after the load is completed… might be worth a try.

Good idea, but unfortunately it doesnt seem to defer the execution of the next loop iteration :o(

I recommend using the level streaming object, as described in this post:

A ForEach loop will work fine here, since no latent actions are involved.

Cheers mate! So much cleaner than the manual for-loop I tried using