How to sort by newest through random items from an array?

I’m (still) making a multi-slot save/load game menu, and currently it kinda looks like this, Game Instance checks if slots named from 1 to 99 exist and add the ones that do exist into an array:

then load screen widget loops through all items from that array and adds a single slot widget as a child to a scrollbox, assigning the Array Element number as an ID to each slot, so they all carry the same number as an existing save slot as ID.

you can later click those slots to set their ID as the active save slot so you can manipulate them, and do thing such as load from them, save into them or delete them.

now, currently they are sorted from oldest to newest (opposite to what I want) but that doesn’t even matter since when I overwrite one of those saves in the middle, they’re now the most recent save and should be on top of the list, except their ID can’t change so they stay at the same position.

So I suppose each Save Game slot should also keep stored an absolute incremental value to keep track of which order they were last saved, but I can’t imagine how I could do that or how would I loop through a second variable from those save slots and sort my list from those.

conveniently all saves store a DateTime of the time they were saved, but I’m also not sure if that could be used. ideas?

What about saving some form of date and time in the save file name?

Only thing is, when you update one, you have to delete it and make a new save game for it.

I already do that

conveniently all saves store a DateTime of the time they were saved, but I’m also not sure if that could be used. ideas?

I could add any kind of data to the save game BP that I want, I suppose I could add an ever incrementing integer if that would help.

I’m just not sure how I can use it to sort the slots which are spawned using values from a different array.

So I was thinking, this is how it is currently:

Instead, I could get the saved date from each slot and store them into another array, and then loop through the items from that array and add the slot widgets from that, like this:

but there are two problems, first the save dates would be stored into that array on the same order as the slot numbers, nothing would change, and second the slots date array don’t have any reference to the slot ID number so I wouldn’t be able to add the widgets based on saved date.

so

  1. how can I sort an array with random dates by their date?
    2 how can I associate that array of dates to their slot number?

Ok bear with me, I used a map (dictionary) to associate datetime values to their slot numbers.

then when the first loop is done, it loops through the array of saved dates and finds their respective slot in the map, finally adding them to their parent scroll box.

Now I just need a way to sort that Slots Date array by date. any ideas?

(if interested, for the complete answer check the entire thread util this post)

Ok so I found this

https://answers.unrealengine.com/questions/953370/is-there-any-way-to-retrieve-the-most-recent-datet.html?sort=oldest

(answered by ClockworkOcean himself) and installed the plugin to my engine. A simple custom “sort date time array” node that ships with the plugin did the trick, it even has a reverse option so you can set from older to newer or the other way around. pretty neat node if you ask me.

image

I just had to add a few clear nodes to clear the date array and the map dictionary before the initial loop so it wouldn’t add duplicate entries, and now it works like a charm. neat!

only question remaining, is there a way to replicate this node’s functionality in blueprints? I’m not a big fan on relying on external 3rd party dev plugins, cuz they can get discontinued and then I’d be stuck to a certain engine version. will sure use this in the foreseeable future but it would be great to have this as a blueprint function.

Well, in fact I guess I should mark this as solved since it’s working, and ask about sorting a datetime array in another thread?

1 Like

Reposting my solution from another thread:

And a running example with nodes in this post:

this is way better than all the gibberish I posted above, kudos

1 Like