Key and door system with Blueprint Component and Interfaces

Finally i am done with my Itemsystem and can now pickup items. the problem is, that i dont know, how i can “use” the picked items.
i was thinking, about making a door with key system, and i have no idea, where in my code i have to store the KeyID and where i have to check if the ID is the same as from the door.

i have a struct with Item and Amount. an BPC for the inventory, where i can add items
i followed the udemy cource for horror games.

Hi @Milko43

Ok seems straight forward enough. The item which is the key needs to have a variable that cobtains the code for the door.

In the door blueprint when you interact theres 2 ways you can do this. Either you pass the actors inventory to the door for it to search for a matching key(passive use) or more direct use , make the player equip the key or use it and pass the code to the door. An interface would be a good way for this. But just passing the actor to the door is also possible , chrck he has a key equipped , if so check the code


that are the codes for my koey and door BP
I also thought about using the key when equiped

What you need to do, on the top code where you have your player ref and inventory. Add a for loop (with break) to the inventory, check each item , if the item is a key, check the code. If the code matches set a local bool called bValidKey then break out the loop. On the completed section branch the bValidKey true unlock door, false do nothing (or whatever you want raise an alarm , fire a laser anything)

Or

If your players has an equipped slot, compare that to key item and check its code if matches the open door etc

i couldnt completly understand your instructions.
i am still at the point, where i cannot even check if i have the same ID

like that?

i think that worked, but i think my save ID is not working probably.

Ok so your inventory, is there not an array of items you have? That needs to go into the for loop as the array input.

I can see you add an item to the inventory, so how do you read them? You kust have a storage array in there and thats what you connect to you for loop