Welcome back everyone in this video Our goal is to add variables in script necessary to show or hide an open door message as well as create the interaction for the actual opening of our b p door. Let's jump right to it and double click on our BP door to open it up. Now straightaway I am going to create a few variables I know we're going to be needing down the road so let's just get those out of the way first. So down here in your my blueprints section under the variables, click the plus variable button. And this first one we are going to call a can open door question mark. This is going to be a boolean variable which it is by default.
We are going to be asking Can we open the door or not? I am then going to duplicate that particular variable by right clicking on it, duplicating it, and we are going to call the next one has door then opened. Now you can see I did not leave any underscores or spaces between words in my variable names. That's just kind of my own naming convention. You can choose to use your own naming convention. But I want to point out something right away.
You can see that I've got no spaces here, but I am capitalizing the first letter of each word. If I was to drag and drop one of these into our Event Graph, and I get it, you can see that Unreal Engine is smart enough to know that I actually meant three separate words. Pretty cool. All right, that is all we need to do with these for now let's go ahead and create. Well, let's do our initial showing and hiding of the text show We a little refresher here, what we got is this door and then we've got this trigger volume right here. And we want to make it so that our text that says F to open door appears when we overlap this trigger volume.
So, with our collision selected, let's jump into the Event Graph. Find some empty spots an empty spot in your graph. I don't need any of these appear. I'm going to left click drag out and delete those. And with my collision selected up here, I'm going to right click add an event for collision collision. And we're going to do a begin overlap.
Just to show you the different ways that you can add events for this. You can also right click on the component itself, appear in the components panel, add events and I want to do add on component end overlap. Okay. Now we only want something to happen when it is us the character that is overlapping This collision not something else, like a physics body or a projectile. So what we can do is drag out of our other actor pin on our on component begin overlap. And let's do something called cast to first person character.
So when something overlaps this collision, it's going to output some information, including which actor did the did the overlapping. And what we're doing here is we're basically checking Hey, was the first person character the one that overlapped this collision volume, and if it was, let's do something. And if it was not, let's do something out here. This kind of acts as a branch in a way. Okay, next I am going to bring in our heads door bend open variable. So just drag and drop it from down here.
I'm gonna get that in I'm going to drag a wire out of it and look for a branch node. So if our First Person character was the one that did the overlapping, we want to find out has the door been opened. Okay, next I want to bring in a reference to our text render, drag and drop that in here. Then drag a wire out of it, and do a search for a node called set visibility. So what we want to say then is, if the air has the door been opened, no it has not been open, then we want to set our text render visibility to be visible, so make sure you check this box. And then what we want to do is dragging a reference to our can open door here, and this time instead of getting it we want to set It by checking this box, we're going to set that to true.
So let's recap here. We begin overlapping that volume, we're going to check to see if it's the first person character. If it is, we're going to continue on, then we're going to ask the question, has the door been opened already? If it's not, then we're going to show them the text message saying how to open it, which is F to open. And then we're going to set our Boolean variable here to can open door Yes, they're going to be allowed to open the door. Okay, so that's good for beginning the overlap.
What about our end overlap here? Well, let's once again drag out of the other actor, and cast to first person character. Then let's bring in our text render actor and we want to drag out of it. Do this set visibility. Once again, and we want to leave New visibility here uncheck basically, when we are not overlapping that collision volume, we want to hide that message that says F to open. Also, what we want to do is grab a copy of this guy up here Ctrl C Ctrl V. And we want to make sure that this is not checked, because if they're not in this trigger volume, we do not want to allow them to open the door.
So all this script right here is just for the showing or the hiding of the door message. So with that done, I'm going to left click drag out a marquee selection, tap the C key and type show slash hide. Open Door message and Compile and Save that Now, we still can't open the door yet, but you should be able to jump back into your level here. And you can see I dragged a copy of BP door into my level, I'm just going to right click and play from here. And you should see that message appear when I'm in the trigger volume, but when I exit out of it, it disappears. All right, so we're getting somewhere.
Next, what we want to do is we want to actually make that door interactable. Let's do this, find an open space below our graph right here. We're going to right click, and in the search bar, just type in input, F. Let's try F, F input F key. There we go. F key is probably good search, you're looking for this input keyboard event, the F key and I always seem to struggle finding those by the way. Okay, so we want to make it so that when we press Enter If something is going to happen, well, we want to see if we can open the door.
So let's drag and drop a reference to our can open door Boolean. We're going to get that dragon wire out of it and bring in a branch node. So first things first, we're going to check after we press F, can we actually open the door Are we allowed to do that, and remember that is being set to either true or false, based on whether or not we are in the volume, they're set to true or outside of the volume, they're set to false. Okay, if we are allowed to open it, we're going to bring in our text render component right here. gonna drag a wire out of that, and I'm going to set visibility. So if this is true, we're going to make sure that that texts goes away.
There's no point in showing that message anymore if they are allowed to open the door, and they're in the process of doing so. Okay, so once they have gotten this far, what we want to do is drag in a reference to our heads door been opened. We're going to left click and bring that in. And we want to set this because the door is just about to be opened here. We want to check that because we're saying, yep, the door has been open. Why are we doing this?
We want to make it so that we can open it once, not just repeatedly, open, close, open, close. So that's why we're doing this step right here. Next, we need to bring in a timeline node because like we did with our moving platform, we need a timeline to enable us to open and close that door. Okay. So let's right click, search for a time line. And let's just call this door hoping we can plug this into the play but obviously we've got some work we need to do with our door open timeline.
So let's just double click on this to open it up right away. This should look familiar from the last video and like we did before we are going to add a float track and I'm going to call this door rotation. The length of this track we are going to keep really short we don't want to spend five seconds waiting for a door to open I'm going to set this to be point three seconds. You can use your mouse wheel here to zoom in and out. right mouse click to kind of slide this timeline slider left and right. We're going to add two keys here.
So holding down the Shift key, I'm going to shift left click to add one key shift left click to add a second key Let me select my first key here and at a time of zero seconds, I want a value of zero. For the second key, select that guy at a time of point three seconds, I want a value of negative 90. Now why negative 90 here because we are going to be rotating the door and negative 90 degrees. So with that, it's very difficult to see where that other key went because it's way way down here. So I would like to frame up on that. So going to left click, drag around both of those keys and zoom to fit, like I did before I did that auto interpolation.
I've got both of these keys selected, and I'm going to right click on either one and I'm going to do this auto interpolate What this means is that we're going to smoothly transition from one number to the other. This makes it so that it's not a harsh opening, it's going to sort of slowly accelerate open and then slowly decelerate towards the end. Okay, so with that done, we can come back into our Event Graph. And you can see we now have this door rotation float output. What we need to do next is ringing a reference to our door because that's the guy we want to rotate open. And let's drag off of our dorm, we're going to be looking for a node called set relative rotation because we are going to be rotating this open and right away, we can go ahead and take our update from out of our timeline and plug that into our set relative rotation over the Course of point three seconds we are going to be rotating our door open.
So now how do we plug in our new door rotation here because this is a float value and this is looking for a rotator. What we can do here is I can let or left click and drag out a wire from our new rotation. And when I release, there is a node called make rotator you want to bring that guy in, we only want to rotate along one axes, and that is our z, the one that's straight up and down. So if I take our door rotation and plug this into our z, we're essentially saying that over the course of point three seconds, we want our door to rotate negative 90 in the z axes. All right. Let's Compile and Save this.
And then let's jump in and play and see What we've got I'm at the start of my level my door is over here there's my test door F to open tap the F key and it does not work awesome I if I have forgotten one step and I know what I missed here is that I needed to do something here in this blueprints class defaults. This is kind of a good to know but these keyboard events, typically unless these are in either a player blueprint or something else known as the controller blueprint, which we are going to be talking about later on. These events are not going to work, we need to do something special. In this case, I need to come on over to the class defaults tab. And down in the Details panel, there is an auto receive input which is currently disabled. I need to set this to be player zero which is us The loan player of the game.
So now if we Compile and Save, I'm going to jump back over to my level. I will right click play from here. So now we see that message appear. And if I tap the F key, it will now open relatively fast. And if I tap it again, nothing happens, just like I'm intending so that is working just like I was hoping. Now obviously modifications you can make to yours are you can increase the length of time with which your door opens.
You don't have to have it be point three seconds, but there is a last look at our door open scripts. So if you want to pause and kind of take a gander at that. Let me try to fit this all on screen one more time, while I drag out a marquee selection, left click drag, tap that C key and I'm going to call this Open Door. That's the look at the open door script. And one more look at the show hide open door script for anyone that would like to pause the video here. Actually, before we wrap this video up, I am looking over my notes and I forgot one more thing that we still need to fix up.
Come on down to your F key events. Let's make sure you select this guy. And over in the Details panel, we need to uncheck this consume inputs by unchecking this this will make it so that for every door we place out in our level, we can we can open them all independently. If you have that checked, you will be able to open up one of your doors, but not others. So make sure that with your F key selected here, you have unchecked your consume input checkbox. All right with that let's Compile and Save That'll do it all for this one guys.
We will see you in the next one.