Connecting a Keypad to unlock a door

Hi, so I am currently making a level in UE4 (4.8.3) and have added in a asset for a Keypad (bought on the Marketplace)and of course a door w/ its own animation (from another free content pack, Shooter Level )

Now I’m struggling to connect these together so that the door will only open when the right key code is entered and access is granted, where and how do I do this?

At the moment I can enter the right keycode and it displays that it is correct/incorrect, but the door still opens when I approach it no matter what(due to its own trigger box, there no collision with the door either, but that’s a later issue)

Any help?

Hello SCB360,

I’m assuming that you have it set up so that when the player overlaps the trigger box for the door, it opens. If this is the case, you could do this with the use of a boolean variable.

First, create the boolean variable inside of the door’s blueprint and set the “Editable” setting on it to true. Make the default value of the boolean False.

Next, open the blueprint for your Keypad, return to the level editor and select the instance of your door in the level. After it is selected, go back into the blueprint for the keypad and right-click in the Event graph. It’ll give you the option to get a reference to that door instance from the level.

After this, go to the logic where you have the keypad’s sequence set up and on the part where the sequence is correct, have it also set that boolean to True. You can do this by dragging off of the Door reference and making a “Set booleannamehere” node.

Lastly, go back to your Door’s blueprint and add a branch between the overlap event and the logic to open the door that checks the value of the boolean. If it is set to true, open the door. If it’s set to false, do nothing.

Hope this helps!

OK, I followed it through step by step and the issue I’m getting is where I have to get a reference to the door in the keypad BP, for whatever reason it will not do it unless ‘Context Sensitive’ is unchecked, when I bypass that, the Boolean I set insists on a target and the get reference for the door will not connect at all

Ah I probably should’ve tried this myself to be sure before telling you. Directly referencing it like that in the blueprint won’t work the way I said it would. Instead, create a variable in the Keypad’s blueprint and set its type to your Door’s blueprint. You can then use that variable to do all of your referencing. Also, be sure to select the Keypad instance in your level and then from the details panel set that new variable to the particular instance of the door in your level so it knows what to reference.

So I managed to create that reference and get it all set up, now the problem is that the door doesn’t open at all, so I know something is working, but now doesn’t open…

This would be the time for some debugging. Try separating the windows so that you can see your blueprints (The Keypad would probably be the best to look at in this case) and your game at the same time. Press play and then at the top of the blueprint look for “Debug Filter” and a dropdown. Select the instance of the Keypad in the level if it hasn’t already been selected. Then return to your game and enter the sequence. Keep an eye on the blueprint and watch what is being executed. Is the boolean ever getting set correctly when you finish entering the correct sequence? Does it ever get set back to False?

According to the debugging, its going through it all just fine (and to be fair it is doing the right thing for the code being entered) but it does the same no matter if the keycode is right or wrong, hell I tried to Destroy a actor (thinking of using a forcefield instead) and even that would not work either

Could you take a screenshot of the event graph where the keypad logic is happening? It could be an issue with the way it’s set up.

So here is the BP for the Keypad and the third image is the Door BP itself

Thank you for the screenshots but I don’t see any mention of using the boolean which I’m guessing is “Last_door_unlock”. Is it just not shown in these screenshots or is it not set up at the moment?

I’ve reset it back to what they were, last_door_unlock was the Boolean I was using

With the current set up, there is no communication of any sort between the Keypad and the Door. As it stands, if the keypad is interacted with and the sequence is correct or incorrect or if the player ignores it entirely, the OnComponentBeginOverlap will be triggered once the overlap begins. Something needs to be between the OnComponentBeginOverlap (and the End overlap most likely) and the Timeline node that will cause it to only be triggered if the keypad sequence is entered correctly. You could use a Branch that checks the status of Last_door_unlock to do this. As far as setting it, you could set it to True just after your “Set” function for setting Local Int to 1. Once again, be sure that it is set to False by default or it’ll just always be true anyway and we’ll have the same problem.

As I mentioned, you’ll need to set that boolean to true from inside your Keypad BP at some point in the logic after the correct sequence has been entered. This will let the door open after the correct sequence has been entered.

It doesn’t seem like you have a reference for your door inside of your KeypadTrigger BP. You’ll need to add this so you can get a reference. Add a new variable and then change the type to Last_door. You can then set the reference from inside of the level editor by selecting the instance of the KeypadTrigger in the level and finding it in the Details panel. You can use this reference to set the Boolean.

So I have set the branches here to true, no where in the Keypad BP do I put anything? To connect them?

So here’s where I’ve tried to add it to the keypad:

Be sure to check the checkbox in that set node for the boolean so that it sets it to true.

Hello SCB360,

Were you able to figure out how to fix this problem? I would be happy to assist you further if you need me to.