Array calculating index incorrectly

Hello,
I am trying to find a grid by doing simple addition to an index. In the example picture the current index is working. It is being set properly on the actor spawning. However, it is not adding correctly when trying to find the next grid to move to.
Imgur

To give a bit more background. I am spawning an actor on a tile. This all works perfectly. When the actor is spawned the current index of the tile which is in an array is added into the actor’s bp. This works fine, the print string when the movement command is called is showing the correct index indicating that the actor knows what tile it is currently on. However, the issue starts when I try to move it forward.
Imgur

To go forward you should take the current index and add 3. However, when doing this I get wildly incorrect answers. Commonly 13-15 when the actor is on tile 5.

Does anyone have any idea what is going on here?
Thanks

“Get All Actors of Class” doesn’t return an ordered array. So, one time it could be ordered [1,2,3,4,5,…], but in the next in it could be [10,9,4,11,…] and so on.

Could you go into detail about what to use here instead? I want to just do some basic math to the array (+3) but I am not sure how to go about that in an ordered fashion.

There are a gazillion ways for grid movement designs.

I’m not going to discuss the rights and wrongs with your approach, other than, there is no reason to call “Get All Actors of Class” everytime you make a move. Call it, in the beginning for example.

Now, to solve your issue with the minimum intrusion in your design, you just need to add an integer variable to your tile, and give to each one a number, the same ones you gave in the picture above (if you want, you can automate the input of this number using the constructor script):

1.jpg](filedata/fetch?id=1807694&d=1599116369)

](filedata/fetch?id=1807695&d=1599116374)

Then, for the movement you just need to search for the tile with the id = current index + 3:

](filedata/fetch?id=1807696&d=1599116382)