How to remove an item from inventory after using it.

Hello. I want to automatically remove an item (door key) from my inventory after I open the locked door. This is the code for the door key.

and this is the code for the door

So when I press left click on an item with a linetrace I add it to my inventory

from there I can use it, examine or drop but for the keys specific I want them to disappear from the inventory when I click to open the locked door.

Can someone help me?

if has key2 == true (on last bp schematic), then from player ref get BPC inventory and remove the item from it (pass in the key class that is assigned to unlock the door)

2 Likes

Thank you very much!! :smiley:

Hello again. It seems that I have a problem with your solution.

When I try to remove the item it removes the first item that finds in the inventory. I think that is because of the index (0) in “Remove Item” blueprint. (In this photo I dont have them connected)
I tried to connect the “Has key 1?” to index and it seems that is working but only if I have 1 key in my inventory. If I have 2 keys and I use both of them, they unlock the doors but it doesnt destroy the key2 in the inventory. Is there a way to fix this problem? I use the same code also in the other door but I change the “Has Key 1?” to “Has Key 2?”

Skip the bool all together. Save the class of key 1 and key 2 to the inventory and then just scan the inventiry if the needed keys are there and remove them.

If both keys have the same class then you need to extend the item class to have identifiers (can be strings to be more descriptive) then add key class with “1” or key class with “2”