Combine to Variables / Values? Order an array?

I’m trying to take the distance of all the elements in this array and then I want to order the list by closest to farthest.

I’m not sure how to compare the organize and compare the values ultimately.
AI seems to recommend a structure (not familiar)
Is it possible to just create a second array and compare the two Index’s of the array? (Idk maybe that won’t work)

Structs let you combine some variables into one ‘structure’, and while this is how would you would solve the problem in a regular programming language, BP does not support sorting them.

Things like this are no fun in BP, but of course anything is possible…
The second array idea can work, build up a distance array as you build your result array, insert into the distance array at the appropriate place (loop and find index to insert at) and then insert into the result array at the same index.

I used actors here, I see now you are using components, so some minor changes required:

Helper function to insert into the distance array and return the index:

“Proximity Sort”:

Distances and Result List are local variables.

1 Like

I’ll just leave it here because it’s awesome and related:

1 Like

If you want to sort array elements in Blueprints, Unreal Engine doesn’t provide a default node for this. However, you can create a macro library in Blueprints and implement a sorting node within it. While it may not be as efficient as sorting in C++, it’s a feasible approach. Here’s my macro for bubble sort:


You can try creating a Blueprint Macro Library and replicate this logic if you don’t want to code it yourself. Alternatively, there are likely plugins available that offer similar functionality.