# How do merge 2 distinct array of object, and then sort it? 

**URL:** <https://forums.unrealengine.com/t/how-do-merge-2-distinct-array-of-object-and-then-sort-it/1318008>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine, question\
**Created:** [September 30, 2023, 7:16pm UTC](https://forums.unrealengine.com/t/how-do-merge-2-distinct-array-of-object-and-then-sort-it/1318008 "2023-09-30T19:16:38Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![pezzott1](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/pezzott1/32/1215068_2.png) [@pezzott1](https://forums.unrealengine.com/u/pezzott1)\
**Post date:** [October 1, 2023, 5:46am UTC](https://forums.unrealengine.com/t/how-do-merge-2-distinct-array-of-object-and-then-sort-it/1318008/4 "2023-10-01T05:46:50Z")

</div>

Without an idea of your knowledge of blueprint, guess a generic way could be:

1. One of the characters or a third class is needed to have a reference to all actors with the data to merge.
2. Iterate the references to [append](https://www.youtube.com/watch?v=OIngYuNKYc8) each to a new array or an existing one.
3. swap the indexes using [your favorite sorting algorithm](https://forums.unrealengine.com/t/sorting-algorithms-in-blueprints/1135992).

And of course do all this inside a function.

* * *

If a third class is used there is also the option to get the array using an interface to avoid the include of the character class.

* * *

Here are some useful links:

- [https://www.youtube.com/watch?v=RwbkvUEgCls](https://www.youtube.com/watch?v=RwbkvUEgCls)
- [Array Nodes | Unreal Engine 4.27 Documentation](https://docs.unrealengine.com/4.27/en-US/ProgrammingAndScripting/Blueprints/UserGuide/Arrays/ArrayNodes/)
- [Optimizing TArray Usage for Performance - Unreal Engine](https://www.unrealengine.com/en-US/blog/optimizing-tarray-usage-for-performance)

* * *

Hope it helps. Let me know if you need anything specific.

---

_[View the full topic](https://forums.unrealengine.com/t/how-do-merge-2-distinct-array-of-object-and-then-sort-it/1318008)._
