Unreal Engine 5 : Key and Door System Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
foreign [Music] guys in this video we'll take a look at how to create a key and a door system in Unreal Engine and for this we'll use a third person template as you can see in the video there is a character trying to you know go through a door and then now with the key they can actually enter inside okay to get started what we'll do is we'll go to the third person template which you can find under games Tab and then I'll just give a name called door toot and make sure the blueprint is selected and let's go ahead and create and yeah it will take some time to create and we have our game right here and if I were to just play you'll see I can move the character around jump around you know with the wasd key but we'll create the door blueprint so to get started what I will do is I'll create a new folder called blueprints and inside the blueprint we'll go ahead and select the Brooklyn class of actor type and then let's give it a name BP underscore door or name whatever you want uh it's just a blueprint name and as you can see the blueprint is pretty empty and we just need to add some component so we'll add the door and the door frame to this blueprint to get started we'll do I'll go ahead and click add and then type in a static mesh and then I can just give a name a door frame and under detail panel go to the static mess and then type in a door frame again and you'll find SM underscore door frame which is actually a starter content in Unreal Engine by default now we'll do the same thing for the door so let's go ahead and click and add and type in the static mesh and then let's rename it to door and then with that door selected under the detail panel on our static mesh I'll go ahead and tie a door and it should be SM underscore door as you can see by default it doesn't align so what I will do is I'll use the Gizmo handle to align and then for that I might turn off that snapping mode and then I'm just checking to see if the door is aligned basically you can ball park with your eye for this portion now we'll compile this save it and we can test it out in our map so I'll basically drag this blueprint and I'll hit play and I'll see you can see that actually the player can enter through the door so there is some issue with the door probably the there is a mission collider in the door and we'll try to add that and also we might set the Collision profile so to do that I will select the door and I'll underneath the detail panel I'll go ahead and then under the Collision presets make sure you select the block all and we'll compile save and then we'll do the same thing for our door frame as well so the same way underneath the detail Collision preset we'll just do block all and then we'll save compile and test it out and still the door is not blocking so there's some issue and actually this was on purpose I wanted you to learn the steps of creating it so actually the door is missing a collider in the mesh itself so we'll select the door under and we'll go to the static mass and we'll double click this SM underscore door now what we'll do is under the Collision we'll go ahead and select the Box simplified collision and then you can see there's a collider on the blue oh green color now we'll go ahead and you know play the map and see if the player enters now I can't so that means the Collision is working for us now for this portion what we want to do is we want to actually create a Key blueprint in which when the player touches the key then key gets disappeared so I'll start with the blueprint class actor and then listening with BP underscore key and then we'll double click on it and then we'll do the same thing basically we'll try to add a key for us we can just add a spear for key and for the size I'll just go ahead and put it to maybe 0.2 you know and then you can save this and bring it to the level and test it out to see if that actually is the right size so you can drag the blue BP underscore key and click on play and you can see this is actually a size of key which is good and if you have a 3D model you can actually use that 3D model in place of the spear I just didn't have so I just went with the spear and next thing what we want to do is we want to add some sort of trigger to the spear that means we when the player Collide we want player to collide on something and so that's why we need to add a spear collider so I'll go ahead and add a spear Collide Collision and yeah let's maybe change the size of this spear collider as well let's change the size of the collider to be something reasonable that we can use maybe two or four or three whatever you feel like and then we'll compile and then we'll go back to the map and you can see there's a collider in it now we actually need to create a logic uh the actual coding person and to do that what we can do is with the spear collider selected we'll go to detail panel and you know we what we want to do is we want to select the on component begin overlap and would click click on Plus and if the other component other actor actually is BP underscore third person character so that's why I'm doing a cast to third person character so I want this key to disappear only when the third person touches it and nobody else and how do I know if it's a third person or third person for me I use the third person template for you what you can do is go to your wall settings and then right there you can see you know my default Pawn class is third person character that's why I use the third person character for casting make sure you use whatever you have by default okay now we have the third person you know casted and then the logic is when the third person you know touches me now what do I want to do then I want to destroy myself basically this is a logic from the key you know when a third person that is a character touches the key then disappears the key and what we can do is compile save and we can test out logic and as you can see when the player goes close to the key then key disappears that means our code is working perfectly fine now what we need to do is uh we actually need to create a logic for the third person character itself so I went to the third person character which you can fly in on your starter template and I want to actually add a variable called has key just so that third person there's some logic of testing we are doing to make sure that the player has a key so I'll go ahead and click on ADD variable and then the has key and it will be of Boolean type and when you compile it by default the haschi is false which makes sense I have you know when the player the when the level starts we don't want the player to have key now let's go to the BP underscore key and now what we can do is we can actually from the we can bring out the logic from the third person character and then we can say you know set key to be true so basically when the player touches the key then we want to set the logic of the player having the key to be true and that's what we are doing right here so we are basically setting the player to get the key to be true we can also refer our debugging purpose we can add a logic you know by using a print statement saying that I'll just go ahead and type print string and then I'll just say player has the key or you can say hashtri to be true whatever you feel like so this is basically for you to test out the logic we can use a print statement to check the logic within the level and this is an excellent way to actually debug your code as well by using Princeton and as you can see on the top left corner you could see again I'm testing here doing here you can see the when I go ahead and play the level in the top right corner top left corner sorry you can see the player has the key the statement is printed that means our logic is working now we need to add a rotation to the door and to do that we'll go to BP underscore the door we'll go to even graph I will right click and then add a timeline node so basically timeline node helps us to create the animation system for the door and we'll just name it our door open you can double click on it and I will create a animation for one second so I'll go ahead and click on the plus to the track and then add a float type because we are only animating on one value which is the the D value of the door so I'll go ahead and name this as to rotation or whatever you feel like you can name it and then the very first start of the curve I'll go ahead and click add key and then make sure the time is to zero and the value is zero and then go to the end of it add another key and make sure the the time is one and the value is 90 and you might be like how did you come up with that 190. um basically 190 is the logic that I'm using based off on the the door so if you were to go on the viewport and insult the door and we are basically rotating the door on the d-axis or yeah if you want to use that so that's what we are doing that's how I came up with the value of 0.90. now we'll go to the third person uh you know the map only thing what we want to do is we want to add some trigger to the door so that when the player steps on it then we are checking to see if the door the player has a key if it has a key then we'll basically you know let the animation play it so we'll I'll go ahead and add a box collider and that would be like a trigger to check to see if the player is within its vicinity so maybe I can change the size to be you know four by four so this is the field of influence that we are checking for the player and yeah make sure the box is selected and we'll do again on you know component begin overlap for the Collider and when the uh so basically same thing we want to do in here as well the logic is hey if the other actor or if if it's the player that is stepping on my boundary basically um we want to do something and that something would be you know opening the door you know but we want to check for the logic if the that player also has a key so this time we'll do get has key and um we also had that you know the door the open doors animation system that timeline that we had earlier but we want to open the door only if the player has the key so to do that we'll add a brand statement so basically type if and that would be the ifs branching now the logic would be having a key if they have a key then we want to basically if it's true then we'll you know do something or that do something is basically opening the door if not we'll say hey get the key or something like that and then to change the you know the rotation of the door we'll select the set relative rotation of the door and um I only want to change the D position of the door so for that you know you can go to that rotation and right click on it and then you know split the struck so you can view all X Y and Z value and then we'll plug that door rotate to that G within this set related rotation now this is the logic for True condition now if it's false then we can basically say hey print the uh you know print saying hey go get the key our player doesn't have a key you know so this is the overall Logic for creating the whole level so now we can go ahead and play and if the player goes it says hey go get the key you don't have a key you know same thing I can't jump through it I can't walk through it okay now if I were to go and grab that key um the door opens and my key was actually within the field so let's change this position and we can you know test it out and see it yep of course the door doesn't open now if I go in there yep and then voila the door opens and there you have it in Unreal Engine now you can create your own door and Key System let me know if you have any comments concerns or anything else you would like to see until then stay cool I'll see you in the next one
Info
Channel: sappydev
Views: 5,953
Rating: undefined out of 5
Keywords: unreal engine, blueprints, keyanddoor, unrealengine5, UE5, sappydev
Id: SKjkvqnYwII
Channel Id: undefined
Length: 15min 50sec (950 seconds)
Published: Fri May 12 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.