Attempting to use array which comes from array being modified?

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:

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.

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.

1 Like

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

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?