How to sort an integer array in blueprint?

Hi everyone,
I am trying to implement an scoreboard using blueprint which will sort player scores in descending order and show only top five of them, no matter how much time the game has been played. So , basically I need a sorted array. I have checked some YouTube videos and some UE4 answers, but frankly to say, I haven’t understood quite clear. I’m quite new to Unreal and this is our first team project. So, if someone please upload a blueprint image of how to sort an integer array with simple methods, I’ll be greatly helped. For someone who wish to help, My scoreboard only contains integers and this integer array is supposed to be worked on saved scores and it’ll be shown when the player dies.
Thanks in advance.

You Can use max to get the top value.

You can then remove it using its index and repeat the process to get the next highest.

245446-untitled.png

1 Like

@HarryHighDef ,Thanks. Didn’t know about that. But I think in this way I need another integer array to serve the purpose of saving and showing the top 5 scores. How to loop that? For loop or ForEach loop?

Yeah a for loop would do it.

3 Likes

@HarryHighDef, Thanks. I’ll try to do that. :slight_smile:

Any Luck?

At least for me it worked perfectly, many thanks.

void UMainMenu::SortServerList() {
	TArray<FServerData*> TheArray;

	TheArray.Sort([](const FServerData& ip1, const FServerData& ip2) {
		return  ip1.CurrentPlayers < ip2.CurrentPlayers;
	});
}