# Attempting to use array which comes from array being modified?

**URL:** <https://forums.unrealengine.com/t/attempting-to-use-array-which-comes-from-array-being-modified/118179>\
**Category:** C++\
**Tags:** unreal-engine\
**Created:** [October 31, 2018, 5:40pm UTC](https://forums.unrealengine.com/t/attempting-to-use-array-which-comes-from-array-being-modified/118179 "2018-10-31T17:40:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sjcobs](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/sjcobs/32/918649_2.png) [@sjcobs](https://forums.unrealengine.com/u/sjcobs)\
**Post date:** [October 31, 2018, 5:40pm UTC](https://forums.unrealengine.com/t/attempting-to-use-array-which-comes-from-array-being-modified/118179/1 "2018-10-31T17:40:27Z")

</div>

Hello, Im experiencing an issue where a function takes in an array and returns a modified version of it and stores it back into the array it took in. For some reason this is not allowed, I was wondering if anyone knows why, what im doing wrong, and how to fix this?

The error I get is an assertion failed:

Attempting to use a container element which already comes from the container being modified.

Here is the part of code that does not work:

```auto

TArray<FAssetData> FilteredAssetData = GetAllObjectLibraryData();

FilteredAssetData = FilterByTag(FilteredAssetData);

```

I have tried creating a temporary array that FilterByTag stores its output into then assign the temp array to the FilteredAssetData array but still get the same issue.

I have also tried to store the FilterByTag output to a temp array, empty the FilteredAssetData array, loop through the temp array and add every item in the temp array to the FilteredAssetData array.

I need to do this because the FilteredAssetData array needs to be updated because it will then go through a second and third different filter to get to the final result of all filters applied to the FilteredAssetData.

---

<div class="post-metadata">

**Author:** ![BrUnO\_XaVIeR](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/bruno_xavier/32/1110230_2.png) [@BrUnO\_XaVIeR](https://forums.unrealengine.com/u/BrUnO_XaVIeR)\
**Post date:** [October 31, 2018, 10:07pm UTC](https://forums.unrealengine.com/t/attempting-to-use-array-which-comes-from-array-being-modified/118179/2 "2018-10-31T22:07:18Z")

</div>

Cpp will not allow you modify an array while you still iterating in it.  
You can do what other langues automatically do for you:

create a copy of the array, once loop of changes are done on the copy, assign original = copy.

---

<div class="post-metadata">

**Author:** ![sjcobs](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/sjcobs/32/918649_2.png) [@sjcobs](https://forums.unrealengine.com/u/sjcobs)\
**Post date:** [November 2, 2018, 1:55am UTC](https://forums.unrealengine.com/t/attempting-to-use-array-which-comes-from-array-being-modified/118179/3 "2018-11-02T01:55:59Z")

</div>

Ah okay, thank you for the help! Got it working 🙂

I really appreciate your help, the issue was actually in the GetAllObjectLibraryData function. I was using the asset registry function “GetAllAssets”, once I switched it to GetAssets with a filter applied the issue went away. So my guess is the get all assets was not finishing before applying my filter to the array?
