Download

HELP! How to pick up key and then be able to open door?

Hello! So, I’m new to unreal engine and I’m just testing out some stuff. I’m trying to make a system where the player will pick up the key (by press E, not overlapping and automatically picking up) and I can’t seem to get it to work! I’ve been working on this (what I think should be simple) mechanic for days.


This is the blueprint from the key

ue4sc2.PNG
This is the blueprint from the door

Okay!

Well one system you could make is to have a key array inside your character blueprint, you can make these keys as structs, strings, or integer depending on how many keys you have in your game and on the complexity you want.

Then you make the key have a variable of that type that you have inside your key array. When the character interacts with the key and you want to add it to the array, you cast to the character and use “Add unique” to add the key into the array. On the key blueprint, you set the key variable as instance editable so that you can change the key-id when placing them inside your levels.

When interacting with the door you trigger a check to see if the character has the key that is needed to open by casting and looping thru the characters key-array. If the right key is in then the interact can unlock the door. If it is already unlocked you open the door.

Hope this makes sense, I don’t have access to UE to show you a real exemple.

I’ve tried that and things similar, but it appears as though the casting isn’t working. I cast to my character to give the array the value I want, then I check that array on the door, but either I get no response from the door when I do that, or it doesn’t seem like it has the value in the array. I have editable instance on all my variables, but it still doesn’t work. I’m not sure if I’m casting wrong or something like that, but casting seems pretty straight forward so I feel like it isn’t that, but I’m not sure.

I figured it out…

The object reference was wrong. It should be “get player character” not “get player controller”. I spent hours on this and it was such an easy fix :stuck_out_tongue: