How is an array populated by ForEach?

Hi guys!

A simple newbie question for anyone is kind to answer.

If I use a ForEach loop to populate an array, what is the way it’s done?

If for example I search for all socket’s name in a mesh, or all actors in a scene etc… what will be the first one in position 0 and why? The second? The third…?

Is it the same in BP and in C++?

Thanks!

Are you trying to use a ForEach Loop to add to your array? Im not sure i under stand your question… maybe even show me a screen shot of what you are dealing with?

This has nothing to do with sockets, but the Foreachloop and Set Array Element in the Index of the obtained entry in the array is something that I find useful often.

First of all, thanks for the answers. Second, sorry, my question wasn’t clear. I attached one screenshot this time.

Using GetActor or GetAllActors, what is the order inside the array?

What if I use GetAllSocketNames?

Thanks!

Hi canitaly,

You can test the ordering by just using the print string node (use “Get Display Name” node for actors).

It seems like “Get All Socket Names” is indexed by the order the sockets were created, and “Get All Actors” is indexed by the order the actors were added to the world.

mmm… so technically there’s not a real way to plan ahead an array order. My idea was to get a clear way to order things automatically, so I can manage multiple situations reducing as much as I can to add things manually.

The ordering of arrays is typically sorted by which element was added to the array first (First element that was added to the array is first at index 0, second element is second at index 1, etc.). There’s really no rules you need to follow when adding elements to your own array, it’s generally arbitrary.

However, if you need all elements in the array to be sorted in some specific order, based on a rule, then things become a bit more complicated (See the Filter Array node in this case).

The documentation on Blueprint arrays might help you understand more, and possibly answer your question. If not, let me know.