Hello. I created a key system for a door in my game. However, when the player approaches the key, it is picked up automatically. I want the key to be picked up only when the player presses the E key. How can I set this up? The two images below show the code I set up.
Hi @Aethertome
I quickly put together a programme to solve your problem. First, I created a Blueprint Interface called BPI_Interaction, which I added to the BP_Door and the BP_Key. I created the Interact function with an input type of BP_VictorianCharacter named Player. (If you are unfamiliar with interfaces, watch videos on Youtube or ask AI, but simply: an interface allows you to create the same function for everyone, and everyone can override the function.)
BPI_Interact:
In the BP_VictorianPlayer, I created a variable array called NearObjects of type actor that contains all the actors near the Player. I then ran the following programme:
PS: replace the E key event by a Input Action (Enhancedinput system)
I created two different functions in the BP_VictorianPlayer:
AddOnNearObjects, input: Actor / AddOnNearObjects(AActor* NearObject)RemoveOnNearObjects, input: Actor / RemoveOnNearObjects(AActor* NearObject)
AddOnNearObjects:
That will add the near actor in the NearObjects var
RemoveOnNearObjects:
That will remove the actor that not longer in the range of the player
Write this code in both the BP_Key and the BP_Door. In the Component Begin Overlap section, specify the collision concerned in your actor.
BP_Key:
BP_Door:
If you have any question, please say it and ping me !
I hope that I helped you ![]()
Happy New Year BTW
Thank you. It turned out just the way I wanted. Happy New Year to you too.








