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
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