Trying to sort an array by an integer variable

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.

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.

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.