Copy all elements from one array to another?

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

How about this:

Thank you! This is exactly what I need.

A bit off topic, followup question if you will :slight_smile:
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).

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

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

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:

Thank you again, this is great :slight_smile: