I have an inventory system in the game that I’m creating, and it works rather well. For sake of organization, I’d like to know how I’d be able to better organize it, as items are simply added to an array and displayed in the order that they’re picked up. Each actor has different properties such as an item name, weight, if it can be eaten or not, etc.
What I’d like to know, is how I can pull each of the actors from the array, get their name, organize them alphabetically, and then put the actors back in the array with that new order, A through Z.
currently, blueprint doesn’t have anything for sorting arrays, and sorting alphabetically would be expensive and difficult in blueprints. i think the easiest way to solve your specific problem, is to put all of your game’s items in a spreadsheet, and sort that spreadsheet in Excel or Open Office. one of the columns of the spreadsheet could be a Priority integer, which can start at 0 and increment for each row. then, in your game, you can sort your inventory by Priority, instead of ripping apart strings to compare letters.
then you can loop through your items, ripping out the Priority value, and putting it into an array of Ints.
use MinOfIntArray or MaxOfIntArray to create a new temporary array of ints, as well as a new temporary array of your Item structs. every time you copy and delete an entry from the list of ints, do the same to the corresponding element in the list of structs.
sorting strings and ints should be a built in engine feature in my opinion, and i have no idea why it doesn’t already exist. it would be nice if blueprint allowed you to override comparison operators, but you need to use C++ for that. currently, strings can be compared for equality, but there is no greater than or less than operators, and there is no MaxOfStringArray/MinOfStringArray, which would also help.
I know, this is an old post but I find a better solution in blueprint and I post it here if someone need a better solution : you can use the node “Get Character as Number” to connvert, like the node say, a character in a number that you can compare and sort.
I found myself problem like yours and found a solution.
You can use implementation from Low Entry Extended Standart Library [here][1]
Create a comparator function and attach it. Here’s the blueprint of my implementation:
For those still wanting to try, this was method I worked out. It’s a bit draconian but it accounts for most things a you’d want with this functionality. If anyone can improve it please let me know!
I know this post is from years ago but… recently I was wanting to put together a function like this and here’s a tip for those who doubt whether it’s possible to create a lot of things using just blueprints:
But as always, this function can be always better.
Someone once told me: “Never listen to people telling you that it’s not possible or that it’s too complicated to do something in blueprints.” There is ALWAYS another alternative, a WORKAROUND and sometimes even easier. Whether you like it or not, blueprints are C++, however, there is this misunderstanding among people. But yes… if you are going to do something more astronomical like RED DEAD REDEMPTION or GTA, C++ is the best alternative.