How do I sort an array by distance?

Here we go. You are looking for a sort algorithm available in the TArray class, called Sort. [Click here to see more information about C++ Arrays in UE4][1]

You will need to create a Blueprint Function Library if you want to use it in Blueprints. First of all, go to UE, right click in any content folder and create a new C++ class derived from Blueprint Function Library.

I made mine and named it as StaticFunctions. When it is successfully created and compiled, go to your .h file and do this declaration:

Then go to your .cpp file, and create the definition:

Go to UE and click in Compile button beside the Play button. Once the code has compiled, all you need to do is call OrderByDistance in any blueprint you wish to use it.

2 Likes