What is the best way to cycle through array one item at a time?

Hey everyone!

I’m trying to figure out the best way to cycle through an array one item at a time. So basically any time a certain event is called, it gets the next item in my array. I’ve tried using a For Each loop, but since it’s a loop, goes through the entire index, instead of incrementing by one.

Here is what I have now:

Any help is greatly appreciated!

1 Like

Hi Breakobs,

the easyest way i would suggest to use is simply creating a variable that is storing the index of the array you want to use next. So this variable should start with the value of 0 and should be increased (by 1) every time your function finishes.
Use the “get from array by index” function to get the member of the array

Hope that helps,

Awesome! This is a simpler version of how I was going about it now. Thank you for putting in the time to show this. I really appreciate it!

Here ya go man.

As ** said… you just create an integer variable in your blueprint to hold the current index. You get the object form the array using that integer, do the things with it, and then determine your next index value. There are two possible cases with the next index value:

  • If the current index is the last index in the array => reset the index to zero
  • If the current index is not the last index in the array => increment the index

Here is the blueprint:

Let me know if you need any more guidance! =)

1 Like

No worries man, I’m happy to help. Please don’t forget to accept the answer so it gets marked as “RESOLVED” =)

How can i acces Current Array index, and set Current array index nodes?

In this example, the variable is saved locally. Just access it from the variable panel. Similar to the “Increment Index” area in the example where there is ‘GET’ and ‘SET’ usage to increment the variable.

■■■■, I created similar solution, just looked for something simpler and ready :smiley: Upvoted!

Any chance we could have a screenshot of your solution as well?

Hello everyone,
I am currently trying to rebuild this blueprint and I hope this thread (as old as it is) is not dead. I want to achieve the following: I want to create a blueprint which I can place in the editor, then “fill” it with several static meshes (by using the details panel). Ingame it should then show the static mesh in slot 01 and the static mesh should switch to the next slot when I press a button on my controller.

As far as I understand I can do this by “filling” an array with my static meshes and then use the integer variable to define which “slot” is currently shown but apparently I am missing some steps because i Can not “create” the “GET” and “LENGTH” nodes shown in the solution.

Would it be possible to give a little bit more background for a complete newbie in blueprints?

thx a million
jajujo

EDIT: I have to create the “Setstatic mesh” Function (here represented as the “Do things” node in the middle… am I right? Oh i am quite confused - sry

This is how far i got: