# 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:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![artest113](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@artest113](https://forums.unrealengine.com/u/artest113)\
**Post date:** [September 30, 2023, 7:16pm UTC](https://forums.unrealengine.com/t/how-do-merge-2-distinct-array-of-object-and-then-sort-it/1318008/1 "2023-09-30T19:16:38Z")

</div>

Hello everyone,

As per title, how do I merge 2 different objects of array into one, and then sort or make a new array out of it with sorted attribute? It goes like this:

ArrayA:  
Display Name: Amy , Score: 40  
Display Name: James, Score: 50

ArrayB:  
Display Name: Alex, Score: 60  
Display Name: Lex, Score: 70

Expected New Array  
ArrayC:  
Display Name: Amy , Score: 40  
Display Name: James, Score: 50  
Display Name: Alex, Score: 60  
Display Name: Lex, Score: 70

ArrayA and ArrayB objects are made up of different character class.

---

<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:** [September 30, 2023, 7:23pm UTC](https://forums.unrealengine.com/t/how-do-merge-2-distinct-array-of-object-and-then-sort-it/1318008/2 "2023-09-30T19:23:03Z")

</div>

Blueprint or C++?

---

<div class="post-metadata">

**Author:** ![artest113](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@artest113](https://forums.unrealengine.com/u/artest113)\
**Post date:** [October 1, 2023, 2:35am UTC](https://forums.unrealengine.com/t/how-do-merge-2-distinct-array-of-object-and-then-sort-it/1318008/3 "2023-10-01T02:35:34Z")

</div>

blueprint 😄

---

<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.

---

<div class="post-metadata">

**Author:** ![artest113](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@artest113](https://forums.unrealengine.com/u/artest113)\
**Post date:** [October 1, 2023, 2:25pm UTC](https://forums.unrealengine.com/t/how-do-merge-2-distinct-array-of-object-and-then-sort-it/1318008/5 "2023-10-01T14:25:22Z")

</div>

thanks for the tips! will setup a third class and see how it goes, thanks for sharing the documentation too, it’s very useful.
