Can foreach be pass-by-reference?

When I try to set an element’s value while looping through array, nothing happens. It seems like looping through references to array elements is the way to go, but I don’t know how to do that. This is what I currently have, but it’s kind of ugly, and I’m guessing the performance under the hood is not good either:

135778-inefficient_ugly_loop.png

I’d like to be able to do something like this, with the New Vehicle Info being set inside the function call:

135779-beautiful_efficient_loop.png

Two ways to solve this come to my mind:

  1. “ForEachLoop” is a macro and you can see how it’s functioning by double clicking on it. Then you can copy the content to a new custom macro so you have the same functionality. Then simply change the output and input types to your need.
  2. You probably need to pass the array element by reference to “Move Actor Along Spline” because you want to change it. When you cannot pass if by reference, simply pass it as “normal” variable and return the changed one. Then you can save it under given index in your array.
2 Likes

Wow thanks! I’ve been doing with a lot of nested structures and your solution 1 is what I really need the most.
In the past, it is too cumbersome to set ArrayElem every single time the variable inside the nested structure changes.

1 Like