# Trying to sort an array by an integer variable

**URL:** <https://forums.unrealengine.com/t/trying-to-sort-an-array-by-an-integer-variable/2606069>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine, question\
**Created:** [July 15, 2025, 11:05pm UTC](https://forums.unrealengine.com/t/trying-to-sort-an-array-by-an-integer-variable/2606069 "2025-07-15T23:05:15Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![AlienRenders](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@AlienRenders](https://forums.unrealengine.com/u/AlienRenders)\
**Post date:** [July 16, 2025, 5:08am UTC](https://forums.unrealengine.com/t/trying-to-sort-an-array-by-an-integer-variable/2606069/3 "2025-07-16T05:08:43Z")

</div>

Here’s a post with a bunch of examples on implementing lots of different sorting algorithms in blueprint. Just change the Blueprint after the GET nodes to grab your InitiativeSet variable. Quicksort is probably the best, but if you have a small array (under 20 or 30 items), insertion sort is probably good enough.

There’s even a zip file with the blueprints.

> [@Sorting algorithms in Blueprints](https://forums.unrealengine.com/t/sorting-algorithms-in-blueprints/1135992):
>
> It is common knowledge that blueprints do not include sorting functions. In my previous experiences, I have been able to create simple sorting functions easily. However, during my current project, I faced the challenge of sorting large data arrays and found that the sorting process was either very slow or unsuccessful. Since I wanted to avoid using C++ code or third-party development, I independently researched this issue. After conducting some research, I have decided to share my findings in t…

If you have access to C++ in your project and your InitiativeSet variable is defined in C++, I’d use C++ as it’s way easier and faster than anything in blueprints.

```auto
void SortByInitiative(TArray<MyActor*> &Actors)
{
  Actors.Sort([](const MyActor *A, const MyActor *B) -> bool
  {
    return A->InitiativeSet < B->InitiativeSet;
  }
}

```

Use \> (greater than) instead if you want to go from large to low numbers.

This would be callable by your blueprint if you put the ‘BlueprintCallable’ tag in your UFUNCTION metadata. Make the function static and it’s callable from any blueprint.

---

_[View the full topic](https://forums.unrealengine.com/t/trying-to-sort-an-array-by-an-integer-variable/2606069)._
