How To Open A Door With The New Enhanced Input System In Unreal Engine 5.1+ (Tutorial)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys and welcome back to another Unreal Engine 5 tutorial in today's video we're going to be going over is how to open the door using the new enhanced input system which is released in unrelenting at 5.1 so this won't work in Unreal Engine versions before this and my other videos won't work in versions after that the basics of it will still work you'll just need to change the little bit of input which I'm going to covering in today's video so if you want to use a more advanced door system which I've done before you can merge the input with this with the rest of that video but basically I'll hit play you know what we're going over by now we're going to go up to the door press e it'll open I'm gonna press e and it will close again this is all we're doing just a very basic simple door but using the new enhanced input system so let me just delete this code and I'll show you how I've done it so the first thing we want to do is we want to actually create our inputs so this is again different now what we're going to do is go to control space to go to our content browser and for me it's third person input actions and now we have our input actions if you don't have a folder like this don't worry you can then just create one or just put it wherever you want and we're going to right click go to input and then create an input action and I'm going to name this one I a underscore interact for input action interact like so opening it up straight away now in here we don't need to change anything we can leave this all by default so we'll save that and close it now we're going to go back to our content browser go to our input folder and then go to IMC default if you don't have this don't worry you can right click go to input and then create an input a mapping context we're going to open this and then what we need to do is add a mapping so hit the plus mapping and this mapping is going to be the input action we just created so for me that is IA interact here like so then what we're going to do is press this little keyboard icon to then select the key we want and I want it to be e so when I press e it's going to fire off this input action for interacting and that's perfect for me and again we don't need to change anything else in here so we can save this and then close it like so and what we're going to do next is we want to create a blueprint interface so we can use the input action we just created to then fire off the interact interface to then interact with a door making it nice and efficient so go back to our content browser I'm just going to do this in content folder right click go to Blueprints and then create a blueprint interface naming this simply interact interface like so open it up straight away all I'm going to do in here is name this function interact and again that's it this is a read-only blueprint we do not need to do anything else in here so we can compile save and close that like so then going on to open up our character blueprint as that is where we're going to actually do our interaction code so again content browser third person blueprints BP third person character now in here what we want to do is make sure we're actually setting the input mapping context to be used if you've done what I've done where you've just used the default stuff that came with the third person project perfect you don't need to do anything however if you haven't so you made it yourself you'll just need to do this bit of code here so on beginplay you want to cast a player controller get the enhanced input local player subsystem make sure it's valid and then add a mapping context on there if you didn't quite catch that pause the video replay it or go watch my other video where I go for that more in depth this video is mainly made for people who have already got that part set up and want to then just do an interaction with the door but I assume everybody will already have this working perfectly so once we've got all this set up what we're going to do is right click and search for interact now what we should see is we have input enhanced action events IA interact here and we're going to get this one here now this event obviously looks a little bit different to what it did before in the older versions all we need to worry about is just using started so started is essentially pressed in the old version so we're going to come out started and what we're going to do is get a for each loop with break like so the array going into this wants to be get overlapping actors and a class filter for this wants to be actor so what we're doing is when we press our interact button we're going to just check all of the actors we're currently overlapping for example our door we're going to go through all of those when those are going to spit out the array elements we're going to come out of this and we want to get a does implement interface the interface being or interact interface we created earlier so what we're doing is we're just checking to see if what we're trying to interact with we can actually interact with so because again we're checking if this is true or false we want to hold down B left click to get a branch without return value being the condition and the branch going into Loop body there if it's false that means we can't interact with it so we don't want to do anything so we won't do anything that will then end this iteration of the loop and it will go through into the next array element if there is any if there's not it will just end if this is true what we want to do is we want to actually interact this so we're going to come out of array element and then just get simply interact and we want this interact message here that will go into true of the branch and out of this we're going to go into break of the for each loop with break so we then stop searching through what we're overlapping so we're only going to interact with one thing at once and what this is also going to do is the interact function here is going to cool that blueprint interface interact for this specific array element here so whatever actor we're overlapping we're going to interact with that actor so I hope that makes sense we'll compile save that and that's all we need to do for the interaction code now what we need to do is just set up our door and actually open and closing it so we'll close this and then we'll go back to our content browser content and we're going to right click create a blueprint class creating an actor and I'm going to name this one door BP opening it up like so this is going to be a very basic and simple door so we're going to add a static mesh like so and I'm going to be adding in the door from the starter content so SM door like so that's all I'm going to do in here I'm not gonna have a door frame I'm not gonna have any walls I'm not having anything just this door what I'm also going to do is add in a box Collision however so we can actually be overlapping this door so we can interact with it as we just set up in our player blueprint code so let me just put this in the middle and then scale it up to the size I want so again the player has to be within this box Collision in order to interact with the door so I think this size is going to be perfectly fine for me just make sure you pick a size which works for you so compile save that and then we'll go over to the event graph to start doing this code so let's delete these three nodes as we're not going to need them but what we are going to do is we're going to need the interact event from our blueprint interface so we're going to go to class settings and this has now changed it used to be Implement interfaces but now it is inherited interfaces we're going to press add and then search for interact interface adding in the one we created earlier and now you'll notice on the left under interfaces we have our interact function or our event here so double click this and we now have event interact so again when that function or this event sorry is called in the player blueprint it's going to fire off this event here which will obviously open and close our door working perfectly so out of this we're going to get a flip-flop so it's going to toggle between the values of A and B alternatively so when first goes in it'll be a when it goes in again it will be B and so on and so forth out of a what I'm going to do is add a timeline I'm just going to name this open slash close door timeline like so a going into play B going into reverse because opening a door is going one way closing a door is just reversing that so we don't need two separate animations we can just reverse the opening animation for closing it so that's why we're going to play in Reverse here if we double click this timeline we can open up I'm going to set the length to one second this can be however long you want it's just how long you want it to do to take to open the door and then we're going to add a new track adding any float track and I'm going to name this one door track like so right clicking on this track to add key to car float time of zero value also of zero right click add key to cover float with a time of your maximum length which for me is one and a value also of one the value doesn't want to be the same as your time it just wants to be one regardless of what your time is so we have something which looks a little bit like this we'll compile save that close the timeline to go back to the event graph here and now you'll notice on our timeline we have this float value here of our door track what we want to do with this is right click and get alert make sure it's under float and the alpha is going to be that door track so again the door track is going to go between the values of 0 and 1 which means that Alpha will be 0 and 1 which will go between the values of A and B A being 0 B being one so it's going to smoothly go between those values a is going to be our close value B will be our open value so if I go to the viewport what we can do is we can see if we select our door the Z value is all going to change because that's the value that will change when opening and closing as you can see here so closed is obviously going to be zero and our open position which I want to be that is minus 110. so those are values I'm using a is 0 B is minus 110 working perfectly like this now we just want to be able to change between these values but also actually have that change the rotation of the door so that's very simple we can get a static mesh here drag out this and set relative rotation relative because we only want to change it in the blueprint not in the world and we're going to right click new rotation split the structure pin the return value going into new rotation Z and the execution going into update of the timeline so every time this timeline updates it's going to be updating the rotation of the door we will compile and save that and that should now be working perfectly for us we can close this drag it into our level and then hit play to test out and see if this is working so let's hit play we'll go up to it press e and it has worked and press e to close again I've got two in the level for some reason it's doing a weird glitch again because I've got the other one in there it's still for some reason reference to be honest this is the one I've just got here to the right we can interact with that and open and close it perfectly like so again this other door is a weird glitch in 5.1 we won't worry about that we've got this one here but as you can see this is working perfectly for us so I think that'll be it for this video which we've done everything you want to do what we've done is we've set up this interaction system in which if I'm over here I can't interact with it but if I go up to the door we can open and close the door interacting with it perfectly like so using the new enhanced input system released with Unreal Engine 5.1 so thanks so much for watching this video I hope you enjoyed it and I hope you found it helpful and if you did please make sure to like subscribe down below so thanks so much for watching and I'll see you in the next one [Music]
Info
Channel: Matt Aspland
Views: 17,282
Rating: undefined out of 5
Keywords: ue4, unreal engine 4, unreal engine, tutorial, ue4 tutorial, unreal engine 4 tutorial, how to make a game, how to, blender, unity, games design, ue5, unreal engine 5, unreal engine 5 tutorial, ue5 tutorial, 3d modelling, graphic designer, door, open, close, and, in-depth, explanation, how to open, how to close, timeline, use, efficient, multiple, doors, in level, level, how to open a door, ue5 door, in, animation, animations, animated, input, new, system, enhanced, 5.1, interact
Id: dkeVrlRFJDk
Channel Id: undefined
Length: 11min 11sec (671 seconds)
Published: Wed Jan 11 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.