How to sort an array alphabetically?

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.

Any assistance is greatly appreciated!
Thank you!

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.

1 Like

Thank you for the prompt answer. I’ll have to sort the items alphabetically and then look into using this solution.

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.

1 Like

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:

this is my blueprint for alphabet sorting my inventory I hope you can figure out this :slight_smile:

306366-3.png

this node return ascii code of char you can use it like me.

2 Likes

In the plugin below you can find an Order node and use it just like that.

https://forums.unrealengine.com/development-discussion/blueprint-visual-scripting/4014-39-rama-s-extra-blueprint-nodes-for-you-as-a-plugin-no-c-required

1 Like

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!





But also, I’d recommend a C++ BPFL node to do this for you. It will be faster and should be easy enough to learn.

1 Like

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.

I used this study by @Supremative as a basis to create my alphabetical sort function: Sorting algorithms in Blueprints

I’ll leave it open here with one of my solutions.

1 Like