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?
asked Jul 11 '18 at 02:00 AM in Blueprint Scripting
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
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.
answered Jul 11 '18 at 08:28 AM
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.
answered Jul 11 '18 at 10:41 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here