Wait for latent nodes to finish before looping in Blueprint?

I need to use a loop to load a bunch of meshes and place them next to eachother, using each bounding box as a basis to determine where to place the next one. Well, it’s hard to explain, but long story short, I found out that I needed to use the “Load Asset” node. The problem is that “Load Asset” is a latent node. Already there I had to move my entire bp function out into the EventGraph and replace any local variables for it to work.

But the problem now is that the loop fires each cycle before waiting for the latent node to finish, so I can’t use the previous meshes bounding box as that latent node hasn’t finished loading in the mesh yet.

How can I prevent my loop from starting the next cycle before the previous one has reached the end?

I tried creating a recursive function, so it would call itself at the end, and use a loop counter variable and a max limit variable. It did work… but only for a very small number of iterations. Anything above that tiny number gave me a “Infinite Loop detected” error and shut it all down (although I’m 100% certain there was no infinite loop). I can’t just increase the limit in the project settings either, as it is a store asset, meant to be included in others projects.

So, I’m desperate for any other ideas! Thanks in advance!

I found a “solution” not long after posting the question.

It’s so simple, I’m amazed it even worked…

Instead of a recursive event calling itself… just reroute the last exec pin to the beginning of the event.

Bam. No more infinite loop complaints!

Hey I have the exact same problem in my project. I need to loop through an assetID array of material instances and only one asset is loaded properly because as you said, the first asset is the only that finishes loading when the forloop reaches the end of the array. How could I apply your fix to a for each loop that is dependant on the length of my array?

Nvm, I fixed it. What I used is a “Do N” node and well, ill just post a screenshots:

I basically just use the array index to define how many times the do N node needs to fire. Then as the OP posted I use the exit pin to retrigger the Do N until the array reaches it’s max length. To reset it I always trigger reset right before the whole Do N node does it’s thing.

Just to add for anyone else who finds this useful as I did, that for this to work properly in most cases you need to add an ‘Int+Int’ to add 1 after the Length node and an ‘Int-Int’ node before the Get node to subtract 1 from the count to get the correct indexed item.

I’ve personally used it to repeat through a series of actors disappearing off screen one by one waiting for the previous one to complete it’s animation before triggering the next.

Cheers for the example WixZ

Sorry, you don’t need to add the +1 to the length, just the -1 before the get.