# How to sort an array alphabetically?

**URL:** <https://forums.unrealengine.com/t/how-to-sort-an-array-alphabetically/350158>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine\
**Created:** [March 10, 2016, 4:30pm UTC](https://forums.unrealengine.com/t/how-to-sort-an-array-alphabetically/350158 "2016-03-10T16:30:21Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![PFG\_Icarus](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@PFG\_Icarus](https://forums.unrealengine.com/u/PFG_Icarus)\
**Post date:** [March 10, 2016, 4:30pm UTC](https://forums.unrealengine.com/t/how-to-sort-an-array-alphabetically/350158/1 "2016-03-10T16:30:21Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![ScottSpadea](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/scottspadea/32/1194682_2.png) [@ScottSpadea](https://forums.unrealengine.com/u/ScottSpadea)\
**Post date:** [March 10, 2016, 5:41pm UTC](https://forums.unrealengine.com/t/how-to-sort-an-array-alphabetically/350158/2 "2016-03-10T17:41:31Z")

</div>

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 Float Array Numerically?](https://forums.unrealengine.com/questions/176672/sorting-float-array-numerically.html)**
>
> Hey all, what would be the best way to tackle this? I have an array of floats that need to get sorted into descending order, but I’m a bit stumped on doing this within blueprint rather than C++.

> **[Sorting algorithm](https://en.wikipedia.org/wiki/Sorting_algorithm)**
>
> In computer science, a sorting algorithm is an algorithm that puts elements of a list into an order. The most frequently used orders are numerical order and lexicographical order, and either ascending or descending. Efficient sorting is important for optimizing the efficiency of other algorithms (such as search and merge algorithms) that require input data to be in sorted lists. Sorting is also often useful for canonicalizing data and for producing human-readable output.
> Formally, the output of ...

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.

---

<div class="post-metadata">

**Author:** ![PFG\_Icarus](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@PFG\_Icarus](https://forums.unrealengine.com/u/PFG_Icarus)\
**Post date:** [March 10, 2016, 9:04pm UTC](https://forums.unrealengine.com/t/how-to-sort-an-array-alphabetically/350158/3 "2016-03-10T21:04:56Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Lunder](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Lunder](https://forums.unrealengine.com/u/Lunder)\
**Post date:** [September 1, 2017, 10:37am UTC](https://forums.unrealengine.com/t/how-to-sort-an-array-alphabetically/350158/4 "2017-09-01T10:37:14Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![victoriopui](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@victoriopui](https://forums.unrealengine.com/u/victoriopui)\
**Post date:** [June 7, 2018, 10:46am UTC](https://forums.unrealengine.com/t/how-to-sort-an-array-alphabetically/350158/5 "2018-06-07T10:46:14Z")

</div>

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:

 ![243433-comparefunction.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/8/e/d/8ed8682cb15efd95ea2cd49af56dca8cc05cd32f.png)

 ![243434-sort.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/4/c/24c08cf75641a3a35140086a9c34ef1df1831687.png)

---

<div class="post-metadata">

**Author:** ![DeathWish.MS](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@DeathWish.MS](https://forums.unrealengine.com/u/DeathWish.MS)\
**Post date:** [July 6, 2020, 7:00pm UTC](https://forums.unrealengine.com/t/how-to-sort-an-array-alphabetically/350158/6 "2020-07-06T19:00:51Z")

</div>

![306364-1.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/3/2/6325d0a997ae30a8144413f8ca7b93ddd31595b2.png)

 ![306365-2.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/e/1/1/e11d9848eb2dd76154f3d801c959f1d92886e9e8.png)

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

![306366-3.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/b/7/8/b7898d79845ae6c7f3dea7d575af860c242c12ca.png)

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

---

<div class="post-metadata">

**Author:** ![alto\_andre](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@alto\_andre](https://forums.unrealengine.com/u/alto_andre)\
**Post date:** [December 16, 2020, 9:23am UTC](https://forums.unrealengine.com/t/how-to-sort-an-array-alphabetically/350158/7 "2020-12-16T09:23:14Z")

</div>

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](https://forums.unrealengine.com/development-discussion/blueprint-visual-scripting/4014-39-rama-s-extra-blueprint-nodes-for-you-as-a-plugin-no-c-required)

---

<div class="post-metadata">

**Author:** ![TheBossJoss](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@TheBossJoss](https://forums.unrealengine.com/u/TheBossJoss)\
**Post date:** [April 10, 2023, 8:46pm UTC](https://forums.unrealengine.com/t/how-to-sort-an-array-alphabetically/350158/8 "2023-04-10T20:46:33Z")

</div>

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!

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/b/5/e/b5e53236ce87fccf5bad88ddd99dc6386e76e2ca.png)  
 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/d/7/2/d7224ae8babdc06b42638c10dd61294244499444.png)  
 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/1/e/71e09c7ef86c5f297f094a7826e4da7d38b6ab2b.png)  
 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/e/6/2/e6290d83526e5cd576837ef58fec0c129fb8bbb4.png)  
 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/8/9/a/89a1cb484a5a52519b0af65bfa1da1e1ef606ba2.png)

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.

---

<div class="post-metadata">

**Author:** ![Piires](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/piires/32/1214196_2.png) [@Piires](https://forums.unrealengine.com/u/Piires)\
**Post date:** [January 17, 2024, 5:25pm UTC](https://forums.unrealengine.com/t/how-to-sort-an-array-alphabetically/350158/9 "2024-01-17T17:25:38Z")

</div>

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:

 ![Sort array alphabetically](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/0/d/90d88f16c89144c94d9cb92fb642b531f7812cd6.png)

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](https://forums.unrealengine.com/t/sorting-algorithms-in-blueprints/1135992)

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

---

<div class="post-metadata">

**Author:** ![TypicaUnrealUser](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@TypicaUnrealUser](https://forums.unrealengine.com/u/TypicaUnrealUser)\
**Post date:** [June 18, 2024, 12:38pm UTC](https://forums.unrealengine.com/t/how-to-sort-an-array-alphabetically/350158/10 "2024-06-18T12:38:48Z")

</div>

This function works for me:

> **[Sort Array of Strings | Unreal engine Code Snippet](https://dev.epicgames.com/community/snippets/zOB/sort-array-of-strings)**
>
> This code snippet let's you sort an array of strings with the use of ASCII values.
