Cycle through mesh array in order - Construction Script

Hi, I have a construction script that that spawns flags along a spline and I want it to cycle through 5 meshes in order. I can get it to randomize easily (which is what it is currently doing), but can’t find a simple way to make it simply cycle through.


So far I have this. Is there a node I don’t know about that works like the Random Integer node but cycles by chance?

Thanks!

Hi there,

You can use a For Each Loop

Keep in mind everything connected after the set static mesh will loop through the flow. So, everything else must be connected to the “Completed” output.
If your code already has a loop node, do not add another For Each Loop. Instead, you can get array element and after setting the mesh, you call increment integer.

2 Likes

Hey, awesome, thank you for the fast reply!
Having varying luck with both methods. I have a For Loop but not For Each loop earlier in the code so initially stayed away from option #1. The result works wonderfully, but doesn’t repeat the effect. It just lays out each mesh from the array in order then stops. Is there an easy fix for this?

Using the For Each Loop version causes the flags all to use what seems to be array item #5 for every flag but not sure why (there are only 5 items in the array if that makes any difference):

Great news.
Yes, actually I didn’t know you wanted to repeat after completing a full loop.
You want to “reset” the index counter after reaching the end:

It should work for both cases.

1 Like

Thank you so much, it works wonders! :smiley: Thanks again for the fast response, very much appreciated!

P.S:
Sorry, I should have been clearer to begin with about what I was trying to do!

1 Like