Enhanced Input remapping keys - Unreal Engine 5 beginner tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] before we continue with the video if you like what i'm doing here on this channel please consider subscribing it helps the channel a lot anyway let's get back to the video so in this case we're using unreal engine version 5.03 and we have a third person template here and let's just quickly set it up for enhanced input so we go to our plugins we can type in inputs we'll get enhanced input here we'll say yes and then we'll restart once we've restarted we'll go into our project settings and we'll go to input and we'll make sure that the the default class components or the default class inputs here are going to be enhanced input and enhanced input component for these two then we close that out and we're done with this part now we'll just set up some very basic functionalities so we'll we'll be creating a one input action which we will be using as our jump so let's start off with that so go right click and under input now we have input action available here so we choose to call it ia jump inside of this one we essentially just need to have it as a value type of bool so it's either true or false that will be fine for us so we can save and close this out then we want to have a mapping context for this so we go to input and input mapping context this is where we can actually define how our input action is supposed to be used and so input action not introduction input mapping context and then let's quite standard so in this context now we can say that we want to have a mapping for example jump we can say that we want to have it for example on spacebar and that will essentially be enough and and now we have a jump so if we were to open up our blueprints for a third person character we can see that we have a functionality here we have a b can play which we will be using later but for now we can right click and say just input action uh no ia jump we probably need to find it as yes there we go so now we can see we have an input enhanced action event so this one will be triggered when when that input action is uh used now for jumping here we want to essentially say untriggered we want to call on the jump functionality which exists normally in a third person character and we want to have it so that when this is completed we want to have it stop jumping this essentially means when we stop holding the key this is normal functionality to how it normally works in a third person character blueprint now we don't have this jump action available to us currently so what we need to do is make sure that we're actually making use of this context so by getting our controller for this pawn so the pawns get control over here allows us to get a controller of the type controller so the base controller we want to cast this to a player controller because a player controller is needed to get the enhanced inputs from a player controller we can say that we want to get enhanced enhanced local subsystem so this allows we allow we're allowed to get this as long as we know that we have a player controller or any derived classes of course from this we can say that we want to add a mapping context and in this case we can say that the mapping context that we want to make use of is the one that we've created as standard which currently only has the jump in it and that's all the settings this need essentially we we may also want to save this player controller so if we right click and choose promoter variable place it somewhere here and we can say let's call it just player controller so now we have our player controller for a little bit later if we would need it okay now we have a very basic setup here we are adding our context and we're saving our controller reference and we're saying jump and stop jumping when this input action happens which exists in our context we want to make sure that our original jump here is either removed or disconnected like this so that it doesn't run we want to make sure that this is the code that is running when we're jumping so now let's just run this to test and we can see that if i press press bar spacebar the character is jumping so this is working fine so the first part is done let's take a look at a representation for this now in our widgets so we want to have a widget that represents our sort of remapping ability in an options menu or something like that and to do that we will just be creating a very simple widget we'll make it of a type user widget we'll call it w underscore remap let's say inside of this one we're going to keep it very simple we're going to have a panel first we're going to take an overlay and bring that in here like so and after that we want to make use of something called an input key selector this is a key or a widget that which component that makes it very easy for us it allows us to have a bunch of different functionality already like a reacting button that reads certain things so you can see that we get some events for free when using this so for this demonstration purpose it's very useful to have this so we're gonna be using that and compiling saving and we're gonna go to our graph here we're gonna get rid of the tick and the pre-construct for now so what we want to do here is first of all we want to uh operate within a certain context of what we're changing so we're gonna be saying that we have two variables to begin with here so we're gonna add two variables the first one we're gonna be calling mapping context okay let's try that again mapping context and the type we want to have is of mapping input mapping context over here we're going to have an object reference for that when it comes to the other one here we want to have an input action and this corresponds of course to our input action that we created our jump so if we type in input action you can see that we have a input action which choose an object reference here now and as default values for these we can say that our input action is supposed to be our jump and our mapping context is supposed to be our stat whoops our standard one now uh the reason we're doing this is normally when you click on a key of widgets you will have these exposed and so so each different if you imagine something like a call of duty battlefield or something like that they have different areas where you can configure different key bindings like your keys on foot your keys in a vehicle your keys while you're flying a helicopter for example so in those cases the mapping context will be sort of the grouping where those things could exist and your input action here in this case would represent one of the things that it would do for example when you press spacebar you will be doing the input action for jumping so this widget will now represent one of these remappings in one such list essentially so that's why for mapping context we will have our standard and for input action will be jump so that this widget knows that these are the things that i operate within so to start off with we're going to take our mapping context and from this we can get something called mappings now this here is an array and this array here is an array of enhanced action key mapping structures because you are able to have multiple ones in one mapping context we currently only have one but it is possible that that there are multiples of course because like you would have multiple inputs for driving the helicopter but we will be going through all of these because we simply do not know for sure how many we have like so and what we essentially want to do here is we want to take the element of one of these and we want to break it that's where we can see what it contains so we can see that this is the information it has and it corresponds to an action mapping with a context [Music] and when it comes to the triggers and and extra modifiers and such things in this case we're keeping it simple we're just after the input action here or the action as it's called we just want to compare this one and we want to say because we're operating within a context remember but we're only wanting to change one specific input action and this is the jump in this case we want to make sure that this is the one in this mapping that we are actually trying to change something with so that's what we're doing first we're just going to filter out all the uninteresting mappings that are not matching this specific key here um then what we want to do is we want to display on our key selector over here what key that is to settle like a start scenario right so we'll get the input key selector and we'll set selected key and this will essentially set it to be whatever key that we're after and how to get that information we can get it from this key structure over here this key structure if we do something like this if we drag from the selected key here and you choose make input chord you can see that this is the type that this specific widget here is expecting and it's expecting a key and shift and some other things if you want to have that along here in this case we have a key which corresponds to this key over here so now we have that and we don't need to fill in the other things in this example because we're not making use of it uh but that's essentially it when it comes to that but we may want to save this key also for later so we'll just do something like this promote a variable and after we are done here we're going to be saying that once we have found whatever key that is matching here in our current mapping context this will be our current key so now we have started off essentially saying when this widget is constructed we check what is the key set to at the start make sure to display that for the player so let's create some functionality to check this out we go to our character and we'll create a let's say keyboard key for oh maybe or i something options inventory i don't know you can choose any key here i'm gonna choose i'll choose i i think like so so on the ei key here we want to essentially display our widgets that we have so we have our player controller and we can say that we want to create a weakness we want the widget to be of the class remap that we have just created and after that we want to add it to the viewport so it can be seen by the player like so in addition to that we may also want to do something like set input modes game and ui like so and that should probably be enough for our test at least here so if we go and start now you can see that we have our character we're jumping around the space we press i and we get this little key input selector over here we can see that it says spacebar which is what we have set as our input action so if we were to change this in our context here to say that instead of spacebar we want to have the tab key and we press play you can see now when i press i that it says the tab key over here so everything is working fine in that regard now so going back to our widgets again let's expand upon this further so now we want to have the functionality of having the key selector drive our ability to change what key is mapped so the first step is we're gonna go to our input key selector over here and we're gonna say on is key changed now this event over here is an event that runs before this other event on key selected this is not ideal but for demonstration purposes this will be fine essentially what we're seeing here is if the key is getting pressed we're essentially saying we want to remap the key so what we'll do is we'll create a variable and we'll call this listen for remap or something like that and make sure that it's a boolean and we'll just say that once this happens we are actively listening for a remap because now then on key selected click over here this event will run whenever we press a key so if this has happened then when this happening has happened when this is happening after this has happened we are ready to process the key as our new remap essentially our rebinding of the key so we'll drag out our boolean here and we'll have a branch and we'll say that depending on if this is true then we want to do something about this now we also want to set this back to false afterwards to make sure that it's changing so we don't automatically like are able to rebind multiple times so we're only allowed to do this once and after this we have our logic now what we get here is not exactly what we're needing for our input action but instead if we break the chord here you can see that it's like what we had when we created it over here the key is essentially what we're after and what we need to do now is to tell this context that we're working with so we get the mapping context to say that a specific input action in this mapping context which is the input action needs to be changed and the key for that needs to change so calling mapping context here now and typing in on the map key you can see that we have the ability to do so so it takes a context as a target it takes an input action as it's a vector and then it wants to know what is the key that it's now supposed to no longer be associated with because this is an unmapping which means we will be removing it so we will not be using this key because this is the new key our old key is going to be the one that we saved before as our current key like so now doing this is if we go and try it out actually let's let's do that later um what we after that want to do is essentially say this is no longer a key we want to listen for for jumping what other key do we want to have so we want to have all of these again and we want to say from the mapping context map key and this works exactly the same way so with for a specific context for a specific input action what is the key that we want to have associated with it and that's going to be our new key that we have just detected over here so now we have unmapped it we have remapped it and we might want to also save the current key so that we have that kept track of over here as well like so um now we only set the key and the input key selector over here in the beginning after that we don't actually need to do it because the the specific widgets will update itself what will be important is now in this case just that the functionality works so let's give this a try so if we go and start and i press tab it jumps if i press space nothing happens we open up our little rebinder we click on it and we press the spacebar let's say now we can say that is see that it's updated to the spacebar again nothing we did it's part of the action of the or the functionality that we did if we press tab now nothing happens if we press spacebar we jump and that is essentially all you need to do to do a remapping now there are some things to keep in mind regarding this one thing is if you remember we started off with tab as our input action and we changed it to space this has actually now gone into our context and changed that to space so this is actually persistent for the context that you're changing so if we were to go in and let's say we were to not actually map a new key and play again you can see we start off with spacebar and now we press t even though this widget shows t we cannot jump on t because we have not actually set it up as our new key and if we go into our context now you can see that our mapping is completely gone now because there were no longer any input action associated with this because we only unmapped it we never mapped it again so that's something to keep in mind however and here is something you can help me with possibly if you know the answer to this this only stays persistent within the editor if you were to package this game and change the keys like this it will not be kept persistent unlike the normal inputs where you can actually go in and use i think it's save input mappings or something like that i have not found a proper way to have this saved in a packaged game and have it be consistent persistent through gaming sessions so if you know that answer feel free to let me know in the description of how to do that anyway that's all for now i hope this was useful uh take care hopefully found this video helpful if you liked the video leave a like if you did not like it leave a dislike leave any suggestions or comments you have down below subscribe and share this video if you want to see more like it in the future that is all for now keep on learning take care [Music]
Info
Channel: LeafBranchGames
Views: 16,562
Rating: undefined out of 5
Keywords: gamedev, ue5, game dev, unreal engine 2d game, unreal engine platformer tutorial, engine 5, unreal engine 5 platformer, unreal engine 5 beginner tutorial, Unreal engine, Understanding, Enhanced input, Enhanced, Input, Beginner, Best practice, Use case, DEmonstration, Tutorial, Input action, Mapping context, Player binding, input context, remapping, keys, remap, keybind, keybinding
Id: gmuL2YJBnrs
Channel Id: undefined
Length: 20min 20sec (1220 seconds)
Published: Fri Aug 05 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.