Well, I stay up too late sometimes.
Here’s your Blueprint. I was going to give you the C++ syntax equivalent in case you wanted to transfer it over at any point later down your production pipeline (for aforementioned performance reasons if you run this every frame) but C++ doesn’t get the Max of Int Array function. I could probably locate it in the source code and copy its syntax but I can’t be bothered at the moment.
Local variables:

Function inside a graph:

This version would only run on the server and send results that you could then bounce to the clients. If you don’t need multiplayer support just trash the SwitchHasAuthority() node. Make sure though, if you’re doing this in multiplayer have a sort of “passthrough event.” For example, an event:
- Titled: AuthSortScoreArray
- RPC: Server
- Reliable: Unreliable RPC if you’re running this often like on a tick. Reliable RPC if you don’t hit this often AND if it’s required for gameplay-impacting stuff.
- Create an Event Dispatcher that will take your array of sorted scores, and bind it wherever you need it - for example UI/widgets. In hindsight, I should have included that at the end already.
So here’s what’s going on:
- Enter the function.
- Local boolean variable: bSuccessful. Avoids having multiple Return nodes. Default false, always assume failure.
- Switch on Has Auth. For ensuring we’re the server. Always auth in a singleplayer game.
- Enter For Each loop. Runs through each vehicle, gets its score, and adds it to local array LocScoresUnsorted.
- Loop Complete: Enter While loop. Runs while the Length of LocScoresUnsorted is greater than 0, i.e. loops until the array is empty.
- While loop. Gets max int from array, adds to new array LocScoresSorted and then removes it from LocScoresUnsorted. On the next loop body call, there will be a different max int because the last one was removed.
- Loop Complete. If LocScoresSorted is not empty, set bSuccessful to true.
- Return. Outputs results, and as a local function none of those local variables will be saved - they’re destroyed and reset when we exit.
I’m sure you know how much of this works but I don’t think it ever killed anyone to have an explanation of what’s going on.
Cheers
