How to use Loops to filter out an array

I’m creating a pick up system that checks if the player is holding an item, and if so, prevents the player from interacting with other pick up items. I’m trying to use a ForEachLoop to filter out a list of arrays that holds all the interactable objects that the player has overlapped with and put them in a separate array list.

Once the player picks up an object, the function creates a list of all the actors that don’t belong to the PickUp parent class from the interaction list and uses that updated list as the new list to interact with, preventing the player from interacting with the items of the secondary array, that is, those that belong to the PickUp parent class.

I don’t know if I’m using the ForEachLoop correctly or if I need to add things to it. Here’s a screenshot of the blueprint function that supposedly filters out any object that belongs to the PickUp Parent if the condition that the player is holding an object is true.

At a glance it appears that you complicate this. If the character can only have one item why not save a reference to that item and if the reference is valid then don’t allow any additional pickup?

Well how to do that? My interaction system is based on an ‘interaction list’ that has all the actors that you can interact with (this is done when the player overlaps with an actor, that actor adds itself to the list inside the character’s blueprint).

I tried to make it so that if the actor picks up the item, that item saves itself as a reference in the character’s blueprint and the function then goes through the ‘interaction list’ and removes all objects that belong to the same class as the one that got picked up.

But I either failed to implement the blueprint correctly or I just don’t get how the for loop works

You should really just store a map of booleans + a string named after the “parent classes”. Each item will contain a string for the name of the class it belongs to. When the item is overlapped get the string name, compare it to the MAP data and see if the boolean of that string pair is true or false. If false, you don’t have it, you can pick it up, then set to true. If true, you are already holding an item of that class and you prevent pick up. When you use or drop the item, go back to the MAP and set the boolean to false. This way, you can only have one item of each class at a time.