Unreal Engine 5 - Beginner #98 - Create PlayerController

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
so hi everybody and welcome back to design religion five tutorials is for absolute beginners this is video 98 and in this video we are talking about creating a player controller we already talked in our last video about the input and the input for the first person character and we learned also that this input for the first person character is more or less universal what i mean with that is we can reuse it in many other projects as well so not only for character for pawns and many many other things and these are really the base inputs for example move forward backwards and then only the action mapping a little bit different most time for example you don't need a shot button for all games and something like that so and all this kind of stuff was in our player character and here we are transferring actually all this code what we have here to the um player controller so let's get started let's create a player controller and the question is before we created why we should create a player controller because in this project we have all the inputs for our carrack we have all the inputs in our uh character yes in the blue the blueprint of our character so why why we have to create now a special separate class which is the player controller class and there are different reasons for example if you want make a multiplayer then you need a player controller because the multiplayer they have different controller ids and then if you are a character is that that means not that your player controller will be uh destroyed that means only that the character is destroyed and you can let uh get assigned a new pawn with your controller and there are many many other other reasons too so uh you can read this on the documentation but most time they say for multiplayer and they saved that for a single player for example it's not so important uh so you can keep all the inputs in your character but we learned today creating a player controller because when we go here to the world settings you end here we set the game mode and then you see here we have our default pawn class the heart class and here is the player controller class and this player controller is a default class which is doing actually nothing i think uh it's yes it's not really doing anything here and we will create now our own one and then put it exactly to this place here so let's get started first of all i open up here this first person folder i think i keep in blueprint and here i then click right click go to the blueprint class click here and here in common we already see a section which says player controller and we click on it and i call this pc for player controller underscore and my created controller migrated player controller it's a long name but it's okay for this thing you can think up name which is a little bit shorter but that's okay so now i have created it and we see in the viewport we make actually nothing because the player controller need only inputs for what we want control because the player controller won't control something and in our case it's a character but the player controller can control all other things as well for example we learned a little bit about the player controller in ai because an ai need elsewhere player controller and here we make a player controller for the character so so we have now created this play controller and now actually we need here all this thing here what we have in our player controller you can go there and one way to do this is you just delete here all and make it from scratch but i said this one is universal what they set up which means you don't have to you just use that what they made because this is so like a template template in in the sense of you can use it reuse it at all times you reuse it and change it and this one we are going to do which means we are just using this code here already too which means i can just copy this one this is the easiest way probably you just press here ctrl c for copy then you switch over to your player controller ctrl v to paste and then do you have all the code but now look what happens when you press compile and you get here a massive list of arrows but this arrows are only here because we have now created a separate class which means we have no more access of this self note for example this blue things this blue notes here are errors because there is old timer self reference which is not working anymore because self in our character was our character a blueprint so it was referring to the character here to the yes to the blueprint for the character and that's not working this is one reason why we have here so many errors but there is one more arrow here they created some def some variables which are just loads so you have just to recreate this one here so here in this case you create a variables load and then right here default values for sum and which arrow you have to here let's see this one is something what i made that's not so important at all here you have this one we can't just delete at all and input action place sound on right click that is not arrow that's okay let's see and this one is the dispatcher okay this one um you have we have no dispatcher here then you have create a dispatcher as well here or perhaps solve this one in another way so you see there are many arrows and this is one way to solve it and the other way is for example you just say wait a minute we have here so many settings i don't need most let's say in my player controller i want just walk in front back and left right and perhaps mouse look up which means i need this axis here only this uh move forward and i kick out for example let's see this is four up down that's okay move right left it's okay turn right left move right left is okay but turn i don't need to turn let's kick it and then turn right left mouse yes let's keep this one this look upright with gamepad no and look up down mouse yes that we keep as well perhaps and here on this one let's say um let's say jump yes i need perhaps jump uh play sound i don't need this play sound here with this is this one and you say perhaps you need only now this little version here so you see and with that's made we can of course compile again and we get now some warnings and the warnings are which means we just deleted which means we can just get rid of some sections here at all so now we have some less errors and with that set you have to solve this arrows now here which are a little bit less than before but still you see this is the self here and how we solve this self here fast i show you this one very fast you go here and create just references most time it's all-time reference problem and you know we already talked about references one easy way is begin play and then you create just the references which are missing for example this self here is um we need a reference for this character all right let's create it get player character and then promote this one to variable and right here perhaps red and underscore player character the area app may just reference so i know it's a reference for the player character and then we have this we compile save and now we can of course uh put this reference in here get and then connect this one to this target itself and we solve that very easy here and the same goes for the other places too who needs a self reference for a character that was a pawn reference but let's see if this is working let's hope it's working if not i have probably changed something so and if i compile it see how many arrows yes you see the arrows here on top are gone that's interesting and fine and what i want show so we created a reference of course you can make here another way of reference we learned this tool you can use a function library because the player character and what was it game mode and probably some other mores are all time used used use so you make a function library and then just call the function library here and then you would not even create this one and then you can all time use the function library and then promote this one to a variable and then make this one here as well but this one is the standard way function library is the more probably the more convenient way and here we have one more thing this one i want skip now because this one means we have to create a dispatcher i skipped this because you know how to create dispatcher this part we have already i made already about a video about this and this one is the same thing just with the touch input but a touch input i am not using at all so i would even kick this out to make the code a little bit less and and i'm almost finished and now i show you something very interesting which is um using a little bit the editor a little bit better what i mean with that let's write here big and play here comment for this one here on top because this one is just commenting and making it more visible so and right now i say i want deselect this section right what you normally do is right clicking here and then we compile and that is more or less deselected now very easy way and it's almost good and fine but you can deselect actually sections another way too which is what you would do in programming in text programming and here's a similar way like you are it's like commenting out this section so you are selecting a portion and say disable this selection here for example and now this is possible in the editor too and we learn a little bit about the um about editor preference which you can find here in edit you go here and edit we almost we many times talked about this project settings now let's talk about this editor preference editor preference means uh you are setting it up so how you like it and that means you try to make it as comfortable and as best as possible for your own needs and here i want to show you now one thing which is really handy for blueprinting uh probably you know it if not then you learn it you can write here on top and disable and when you write for example disable we have here a general keyboard shortcut and before we go to the keyboard shortcuts i should show you the normal place which is actually in um the normal place how you can disable and enable nodes is actually here in blueprint editor settings here on general here the third row and you click on this one and then you go here down where it says experimental and then you go and click here which says allow explicit uh yeah this explain what's right there explicit in pure note this one here and you tick on it and if you tick on that then you can something do like uh let me show you this not here we go to our player controller which looks a little bit like this one very simple compared to the other and now you can select this node right click on this node and then you have this option section here in the middle which is new and here it says disable do not compile and now you see this one is disabled you can right click on it and go to enable and enable always means it is available but then enable only for developer only which means if you make this one careful make not this mistake developer only means if you if this will work in your development which means here while we are coding it we are editing it and so on but this node will not work when you release it so change this definitely to enable always and you see it says no development here right that's very important when you do this one because this one can cause problems if you activate this one only for development only all right so that's very important and yeah this is very handy because now i can select if i said hey let's deselect the whole code here instead of going one by one and deselecting all i can right click and say here disable and now i disable the whole part here that's very handy that's we are doing this in programming with commenting uncommenting a section and here in visual in this visual scripting you can do it this way which is very nice as well and then you can select all again right click and oops here right click and then go here to enable and don't go to development that's very important that you make not this mistake here because make always this is the normal section so and one more thing here before we continue of course you can set up shortcuts too and if you want get really good most time you will set up shortcuts for in editor preference is also good or the project settings is also good for shortcuts and in editor preference you can write for example this able and now the same thing what we made with right click here is a section which says general keyboard shortcuts and here we go to this this line here which says disable nodes and in my case you can choose here whatever you did i set up control car for a shortcut so when i press ctrl k it will disable but don't forget you have set it up perhaps for enable as well then you write enable on top then you scroll down a little bit and you can see here general keyboard shortcuts for enabling and here it is the section for enable nodes always of course you have here enabled for the development and i only set up for always because i want most time it not for development i don't care really about development because later i know it but of course you have this option as well it comes handy in certain situations and yeah but i make always and then i set it to control you and if you have this shortcut then you can go here and with shortcuts of course it's faster i press now the shortcut which is ctrl c and i deselect it instantly all things and then i say oh wait a minute i want to only deselect this one or not this one then i just select the other parts here and then i enable it control in my case uh you and you see it's activated that's very handy that's very powerful and now this one is deselected which means i can compile and all the errors are gone because the other parts are okay but this one is deselected this one would still make a compiler but this works now and we can almost test our comp player controller now but we have to one more step and this one more step is uh of course using our player controller for example here in the world settings when we go down to the player controller class it is still using this player controller and i want that it's use my so i select my of course and my was this pc my player controller no that was it not my was a pc my created a player controller uh yes i think this one is the one which i created ah i'm a little bit irritated why this symbol is here a little bit different i hope i made all right because this one is my blueprint class player control yes the parent class player controller all right i think it's it's right all right so if that's that we test it so now i can do almost all things here i'm not sure if this is right and let's see if this is right so you see i'm using now my player controller and i can do almost all things and i think that's not right it can't be normally i should not be able to shot and the reason for that is of course i made here a mistake and can you see the mistake it's very easy i still have the whole code here in my character you can delete it or what i'm going to do right now is just disable it what we learned right i press ctrl comment and all are disabled here and now all the setting what we have here is disabled i compa press compile save and now i press and now this one is only using my player controller and my player controller can't shot i press the shot button i can't use it that's the player controller which i set up and you see it makes almost all the same things but it's much much more little because i said i just need this functions here and the short function yes i must uh get rid of the arrows here which mostly means again a reference here and then yeah perhaps i can make this fast uh perhaps not control uh uncontrol it compile it and you see it says here also a reference to cell probably i can but perips not but let's see i just get this one player character yes hold insert so it says it's not that i need to create again yes whatever all right with that said here we have to create another reference and i skipped this section out creating again a reference and so because the video is too long i think you get the i have an understanding about this one and with that said we know now how to create a player controller you just create this class you set up this one and perhaps one more info that's very handy i said this in project settings and when we go down to this input again where we are and where we have this edge mapping and this axis mapping and you see i messed up here heart right so this is not really the default settings and perhaps you need the default settings again here on the right side on top you can see export and import what you can do i said this one is universal most time you can at start for example you create a first person shooter game and then export it here on a file and then you change here and when you mess it up like me then you press you this input and import it from a file and all the basic settings are again here and that's a very handy way to get this back for example in my case i have not created this export file which means i can now cre go to uh my launcher create a new first person template and then i go here to the input section and then i press there export and that will create a file then i close it and come back to this project here and here i click press import because then i have the file and then when it's imported all the settings are back to the default that's why i said it's very important that we know this one here it's universal and we can all time get rid of it extend it and import it back in my case i will probably import this back because i kicked out now many other things perhaps i need them for example i have kicked here out all the controller settings the second ones because now i have only mouse and keyboard but no controller which is sometimes very handy and many play when you want play on pc with controller two and yeah i will probably bring it back and that's very important that you know this as well so the player controller is set up we can use this player controller and with that said i stopped this video here and have you have any questions or on a complaint like all times write it in the comments and good luck and bye
Info
Channel: Mehmet Kont
Views: 1,315
Rating: undefined out of 5
Keywords: UE5, Tutorials, Game, Dev, Development, Blueprint, Design, Animation
Id: Dfj4APbfuVg
Channel Id: undefined
Length: 25min 46sec (1546 seconds)
Published: Tue May 31 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.