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.

Hi Steve,

The failed assertion you’re getting is caused by you attempting to assign the array to itself. Why do you need to return the array you’re modifying, though? Is there a reason you cannot modify it in-place in your filter function?

Hey again Darkwind!

Yes, it is being modified in the filter function and returning the filtered results and once I have the filtered results I can filter those results with another filter If I need in a loop through all selected filters. That’s why I need to store the result of the filter in this function, because I have a few filter functions I made that the user can choose from with the option to apply multi filters to the data. (That’s what this code is inside, a multi filter function, that takes in an array of filters the user want to apply).

I really appreciate your help, I actually go this fixed though, the issue was 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 them?