# Copy all elements from one array to another?

**URL:** <https://forums.unrealengine.com/t/copy-all-elements-from-one-array-to-another/75925>\
**Category:** Blueprint\
**Tags:** unreal-engine\
**Created:** [October 13, 2016, 3:26pm UTC](https://forums.unrealengine.com/t/copy-all-elements-from-one-array-to-another/75925 "2016-10-13T15:26:04Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_2c124cb81](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_2c124cb81](https://forums.unrealengine.com/u/anonymous_user_2c124cb81)\
**Post date:** [October 13, 2016, 3:26pm UTC](https://forums.unrealengine.com/t/copy-all-elements-from-one-array-to-another/75925/1 "2016-10-13T15:26:04Z")

</div>

Hello,

I have two arrays, one has greater length (let’s call it A) and the other has less elements (B). Is there any node that can copy the elements from A to B. Now since B is smaller than A, it should just copy the first n elements from A to B. For example let’s say the array A has these values (0,0,0,3,8,6,7) and B has (9,1,4,2). I’d like to be able to copy the elements from A to B so that B would look something like this (0,0,0,3).

Thanks

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_5882066e](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_5882066e](https://forums.unrealengine.com/u/anonymous_user_5882066e)\
**Post date:** [October 13, 2016, 3:58pm UTC](https://forums.unrealengine.com/t/copy-all-elements-from-one-array-to-another/75925/2 "2016-10-13T15:58:01Z")

</div>

How about this:

 ![Unbenannt.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/a/b/f/abf1deaa4d4151b852c000b4500de9821420f44b.png)

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_2c124cb81](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_2c124cb81](https://forums.unrealengine.com/u/anonymous_user_2c124cb81)\
**Post date:** [October 13, 2016, 5:13pm UTC](https://forums.unrealengine.com/t/copy-all-elements-from-one-array-to-another/75925/3 "2016-10-13T17:13:10Z")

</div>

> [@;608728](#):
>
> How about this:
> 
> ![Unbenannt.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/a/b/f/abf1deaa4d4151b852c000b4500de9821420f44b.png)

Thank you! This is exactly what I need.

A bit off topic, followup question if you will 🙂  
How can I invert the elements in the array so that now B (0,0,0,3) would look like this B (3,0,0,0).

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_f54268a3](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_f54268a3](https://forums.unrealengine.com/u/anonymous_user_f54268a3)\
**Post date:** [October 13, 2016, 5:23pm UTC](https://forums.unrealengine.com/t/copy-all-elements-from-one-array-to-another/75925/4 "2016-10-13T17:23:38Z")

</div>

That’s reverse.

In C++ decrement the index instead of increment it in the for loop. I haven’t tried it in Blueprints, but looking a the node try setting the start index to the array length -1, and the last index to 0. That should walk through the array back to front if it’s an included feature.

The documentation doesn’t say: [Flow Control in Unreal Engine | Unreal Engine 5.0 Documentation](https://docs.unrealengine.com/5.0/en-US/flow-control-in-unreal-engine/)

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_2c124cb81](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_2c124cb81](https://forums.unrealengine.com/u/anonymous_user_2c124cb81)\
**Post date:** [October 13, 2016, 5:40pm UTC](https://forums.unrealengine.com/t/copy-all-elements-from-one-array-to-another/75925/5 "2016-10-13T17:40:21Z")

</div>

> [@;608814](#):
>
> That’s reverse.
> 
> In C++ decrement the index instead of increment it in the for loop. I haven’t tried it in Blueprints, but looking a the node try setting the start index to the array length -1, and the last index to 0. That should walk through the array back to front if it’s an included feature.
> 
> The documentation doesn’t say: [https://docs.unrealengine.com/latest/INT/Engine/Blueprints/UserGuide/FlowControl/index.html](https://docs.unrealengine.com/latest/INT/Engine/Blueprints/UserGuide/FlowControl/index.html)

I just tried it, it doesn’t work, it won’t iterate through the array:

 ![0e939957313b84c671f144839f320d2888968ee6.jpeg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/0/e/9/0e939957313b84c671f144839f320d2888968ee6.jpeg)

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_5882066e](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_5882066e](https://forums.unrealengine.com/u/anonymous_user_5882066e)\
**Post date:** [October 13, 2016, 5:42pm UTC](https://forums.unrealengine.com/t/copy-all-elements-from-one-array-to-another/75925/6 "2016-10-13T17:42:34Z")

</div>

> [@;608814](#):
>
> That’s reverse.
> 
> In C++ decrement the index instead of increment it in the for loop. I haven’t tried it in Blueprints, but looking a the node try setting the start index to the array length -1, and the last index to 0. That should walk through the array back to front if it’s an included feature.

This won’t work within Blueprints. The LoopBody would never be entered this way. For a reverse ForLoop you would need to iterate from (B-\>LastIndex)\*(-1) to 0 and multiply the index of the loop with -1 in the LoopBody. Anyway that would invert the order the array elements are copied but it won’t change the result.

To get the desired result try this one:

 ![Unbenannt3.png](https://d3kjluh73b9h9o.cloudfront.net/original/3X/1/f/1f91b3a35c914d00931edecf27e19fdcc445aa69.png)

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_2c124cb81](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_2c124cb81](https://forums.unrealengine.com/u/anonymous_user_2c124cb81)\
**Post date:** [October 13, 2016, 6:01pm UTC](https://forums.unrealengine.com/t/copy-all-elements-from-one-array-to-another/75925/7 "2016-10-13T18:01:08Z")

</div>

> [@;608838](#):
>
> This won’t work within Blueprints. The LoopBody would never be entered this way. For a reverse ForLoop you would need to iterate from (B-\>LastIndex)\*(-1) to 0 and multiply the index of the loop with -1 in the LoopBody. Anyway that would invert the order the array elements are copied but it won’t change the result.
> 
> To get the desired result try this one:
> 
> ![Unbenannt3.png](https://d3kjluh73b9h9o.cloudfront.net/original/3X/1/f/1f91b3a35c914d00931edecf27e19fdcc445aa69.png)

Thank you again, this is great 🙂
