Inventory System is Collecting More than one Item

I have made a pickup system that will display a widget that says “Press E to Pick Up” When the player is looking at a box which is around a particular item. This is done through an interaction cylinder attached to the third person character:

When the third person character overlaps with the specific item in the blueprints for this item there is a begin and end overlap event for the box. When the third person character interacts for this I placed a branch to check to see if what is interacting with the box from the third person character is the interaction cylinder:

If the branch is true it will set the value for the subclass for this actor and then open the gate:

If the end overlap event occurs this will close the gate:

When the player presses “E” the player will enter the gate. After this, the item will added to the inventory through the means of setting a variable in the blueprint and then adding a branch in a different blueprint and the actor will be destroyed.

The problem is that whenever the interaction cylinder is overlapping with multiple instances of this actor and the player presses E, all of those actors will be destroyed and added to the inventory. Is there a way I could change this so the player will only collect 1 instance of the actor if the cylinder is interacting with more than one?

Well the better way is to not put any type of interaction collider onto the player at all. Use a raycast system to detect the object youre looking at directly.

Here You Have The Line Trace That Tracks What Object You’re Looking At

Here is what the itemref variable is. A variable of the master item to store the info on what item you just picked up

246970-pic3.png

Here is the master item, a basic blueprint actor, i went more in depth and have item data for each one with its own specific details but that’s not needed for this explanation.

This way is a much simpler and a quicker way of tracking what object you’re looking at.

To do it using your current system of an interaction cylinder on the player, you could set a single variable on the player to he item that triggered it. That way it only has the var set to the last item to enter the cylinder because the next one to overlap overwrites it then when the player does the Pick Up action you destroy only the item that variable points to.

I think it is better to change your system however to make things less complicated.

You can also pick a random one that is within range.

Usually to manage multiple obejcts going in and out of overlap, I add and remove them from an array.
then when it is time to interact the object, i can pick a random one from the OverlappedItems array I made.
In that way you can make it random which one that is in range gets interacted.

Is there a way I could store this in the blueprint for the actual pick up item like I have done with the apple, or do I have to do it in the third person character. If I can how would I go about doing this because the way I have, is not working properly.

Sorry for the late reply.

I am very sorry for the late reply, I had just moved on to creating the inventory system at the time of your reply since this issue was getting a little repetitive.

“To do it using your current system of an interaction cylinder on the player, you could set a single variable on the player to he item that triggered it. That way it only has the var set to the last item to enter the cylinder because the next one to overlap overwrites it then when the player does the Pick Up action you destroy only the item that variable points to.”

I am not 100% sure how to do this. How would this work in the blueprints by setting a variable on the player.

No worries. It looks like you marked something as an answer so i hope that means you got it working.