For Loop => Remove Item (or index) from array

Hello,

I try to spawn actors on a grid.

  • Each location is specified in an array and is unique.
  • In my project I don’t want all the locations to be filled so the last index will not be the length of array,
  • I want unique actor by location
  • I put it in player controller because I will use it in a Networked game
  • Here my grid is a simple line for demo of my bug.

So in attachment you can see my blueprint and the result in game, this is not a full line, some actors are missing.
I was expected that the line be filled up because the Last Index is equal to the array length.

In the loop the item is not removed.
So 2 or more actors use the same location.
What have I done wrong? Is it a bug or an expected behavior?

Thanks for your help.

PS: In my game I use it as a function to execute it with different class of actor in order to partially fill my grid with differents actors. I don’t wand my grid to be fully filled. But only one actor by loction. So another method can help too.

The issue here revolves around the way you use the random node. It is used twice, 1st time to Get and 2nd time to Remove an array element. You’d expect it to produce the same value twice but that’s not the case. It is working as intended, though.

So you Get one random index and then Remove another random index - different from the 1st.

In order to work around it, store the result of the random generation in a variable and use the value to access the array. This should be the first step to take; if there are more issues, let us know.

Of course! Why I haven’t seen it?!!
Thanks a lot!!