# Sort actors in an array by an internal variable?

**URL:** <https://forums.unrealengine.com/t/sort-actors-in-an-array-by-an-internal-variable/489317>\
**Category:** Editor Scripting\
**Tags:** Variable, sorting, unreal-engine, Array, question\
**Created:** [September 29, 2021, 12:01am UTC](https://forums.unrealengine.com/t/sort-actors-in-an-array-by-an-internal-variable/489317 "2021-09-29T00:01:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![TorQueMoD](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/torquemod/32/710746_2.png) [@TorQueMoD](https://forums.unrealengine.com/u/TorQueMoD)\
**Post date:** [September 29, 2021, 12:01am UTC](https://forums.unrealengine.com/t/sort-actors-in-an-array-by-an-internal-variable/489317/1 "2021-09-29T00:01:21Z")

</div>

Maybe I’m going about this wrong, but here’s my scenario.

I have 8 pawns in the game. Each of them has a float variable called RaceProgress which is their percentage along a spline. I want to get all of the actors of class “MyPawn” and then sort them in ascending order by their RaceProgress. without losing which actor is which. I can’t for the life of my figure out how to do this while also retaining the specific actors so I can then assign them a race position value.  
If I just get the Race Progress of each and then add them to an array, I can use the MaxOfFloat node to figure out which one is the highest, but then I only have the floats and don’t know who their owning actor was.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_b3bc4d7a](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_b3bc4d7a](https://forums.unrealengine.com/u/anonymous_user_b3bc4d7a)\
**Post date:** [September 29, 2021, 2:06am UTC](https://forums.unrealengine.com/t/sort-actors-in-an-array-by-an-internal-variable/489317/2 "2021-09-29T02:06:31Z")

</div>

You might be able to use something like this:

![349581-codescreenshot.png]()

---

<div class="post-metadata">

**Author:** ![Ravi80335](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Ravi80335](https://forums.unrealengine.com/u/Ravi80335)\
**Post date:** [September 29, 2021, 7:15am UTC](https://forums.unrealengine.com/t/sort-actors-in-an-array-by-an-internal-variable/489317/3 "2021-09-29T07:15:29Z")

</div>

- Here it is…!
- Map Pawns to RaceProgress and then Sort Race Progresses
- And then get Pawn from Map with RaceProgress and Set Position based on Sorted Race Progresses Index

![349577-screenshot-460.png]()

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_b3bc4d7a](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_b3bc4d7a](https://forums.unrealengine.com/u/anonymous_user_b3bc4d7a)\
**Post date:** [September 29, 2021, 10:53pm UTC](https://forums.unrealengine.com/t/sort-actors-in-an-array-by-an-internal-variable/489317/4 "2021-09-29T22:53:58Z")

</div>

Would this work if two pawns have the same race progress?  
And also, a quick thought I just had, would an array of a custom struct work well here?
