Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

How to sort a struct?


I've created a highscore struct that stores the player name and their score but I want to display it from the biggest to the smallest.

I know how to do this with a normal array of int's but not with a struct.

Can anyone help?

Product Version: UE 4.9
more ▼

asked Oct 22 '15 at 02:43 PM in Blueprint Scripting

avatar image

90 9 15 19

avatar image acemaria Nov 15 '15 at 12:47 PM

Hi, this is my blueprint , I want auto sort by date in blueprint. and when I add new section will move it to top, not bottom. how can I do this ? Thank you.

log: label: log type: structure entry: > {{date}} {{time}}

     label: date
     type: date
     format: YYYY-mm-dd
     label: time
     type: time
     label: text
     required: true
     type:  markdown

avatar image mbelarouci Dec 05 '15 at 02:59 PM

I would also like to see a visual answer to this question.

I have an array of structs and want to reorder the array by one of the variables within the struct.

avatar image sgtfluffybutt Jan 13 '16 at 11:56 PM

alt text

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

3 answers: sort voted first

There aren't too many good array sorting functions in Blueprint, however there are many ways to achieve this yourself.

The simplest way logically to do this is to create a second array of structs which represents the 'sorted array'. Then run through a for each loop on your original array. In this for each loop, run a "for each loop with break" on this second 'sorted' array. In the second for each loop, check every element to see if your high score property is less than the element you have in your first for loop. If it is, then insert the array element you have from the first for each loop node into the array at the index of the array index output from the second for loop, and break the second loop. If this second for loop node completes without finding a smaller high score, then simply add the array element from the first for loop to the end of the second 'sorted' array.

This will result in logic that will stack your structs in order from highest to lowest score and the result of this sort will be in this second array. You can then assign the first array with the value of this sorted array.

more ▼

answered Oct 22 '15 at 02:59 PM

avatar image

3.1k 51 119 487

avatar image sgtfluffybutt Nov 03 '15 at 02:05 PM

Hi there.

Thanks for the answer but I can't picture this in my head. Would you be able to knock something up so I can understand the process a little better?


(comments are locked)
10|2000 characters needed characters left
Viewable by all users

I've spent a few hours tonight figuring this out, and I thought I'd post it here for anyone else who comes across this thread. I made a function that performs a selection sort on a struct array; in my case to sort a leaderboard array by score.

alt text

alt text

alt text

alt text

alt text

And here is the macro I used to swap the array elements: alt text

more ▼

answered Jan 13 '16 at 11:40 PM

avatar image

204 26 28 93

avatar image sgtfluffybutt Jan 13 '16 at 11:57 PM

This is what I did for mine

alt text

avatar image zerofiftyone Oct 16 '16 at 09:23 PM

Hah, just came across this post as I needed this exact thing. Then I realised the post was from myself back in January.

Thanks past me!

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

It's also worth mentioning that Rama's Victory Plugin has a Sort node for arrays, and an option to sort by structure or object field. Works fine for me.

(copied my answer from another thread to this one too, for future generations =) )

more ▼

answered Mar 21 '18 at 05:07 PM

avatar image

91 2 6 9

avatar image Starkium Feb 11 '19 at 12:53 AM

maybe at one point that worked, but I'm here because the sort function from the victory plugin isn't doing anything at all. That or it isn't setting the array to the newly sorted one.

avatar image Starkium Feb 11 '19 at 01:36 AM

found out why it isn't working, the function is not looking for the short name I assigned the value in the Struct, "Ammo" is the name. Instead it is looking for Ammo_5_19145E324396439F5c10A6941E12EBAC I'm not even sure how I would obtain that from a node if I didn't happen to hover over a populated array and notice the contents were that.

avatar image Flashback Feb 11 '19 at 06:18 PM

Yes, it stopped working at some point, I even reported it in Rama's thread. I've modified the code to sort arrays by struct variable name's beginning, that did it for me, and I didn't have time to work on an ultimate solution since then. I guess I'll remove my top comment if you don't have anything to add.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question