Unreal Engine 4 Tutorial - Advanced Dialogue Pt.1 - Interaction

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hi everyone and welcome back for another useful tutorial series one of the first series overdone was a dialogue system and I once I did release it I've got loads of questions from people asking how do I make something that has the prior answer question and had the NPC respond to that question well that inspired me to take another look at the system and redesign it to make it allow for that circumstance where we get the player to answer questions and the NPC to respond now this works very differently from the previous Dalek system and in fact you might prefer this system as it is a lot neater and easier to set up so little demonstration of what happens here I can walk up to my player here push e to interact and I can skip through my dialogue tree and ask question yes or no I'm gonna go yes I'm glad you like look of it what's my favorite color I can choose red for example here and it will respond specifically differently to red okay so this is what we'll be making today so how does this work well this works using the AI behavior tree and repurposing it as a dialogue tree and here is mr. that this is that dialogues that we just saw and it's pretty simple to add stuff to it and change things around but it is I walk you right through it before we get into actually making it so here we've got a dialogue starting so this will actually spawns the dialogue box start things off and each of these sequences is a conversation so here we have different lines of dialogue with a question and selectors at the end to determine what to do with each response and it responds we have a different line of questioning and dialogues like so so makes it very quick and easy to add lines of dialogue and ink adds questions and different responses and different branching power points you do all sorts of things so this is what we'll be making over the course this series so let's get beginning showing so to start things off we need to first we'll make the ability for the player to interact with the IRA NPC so I'm going to make a new folder here and call it npc and in here we can make some pie so I'm gonna go add new blueprint class and character so a simple NPC can open up like so so you get a mesh and I'm gonna go for the defaults don't know American and just put them into position give them an animation class that past blueprint and they'll do it okay so close this on here we also going to have another folder for interfaces and we need to make an interface and interact interface now if you've seen my other tutorials you know why the interface does but for those who are under shade to them you go to a new briefing class and a fade add new blueprints and you'll see in the blueprint interface and I'm gonna know into an interact interface and what these are the collection are functions that you can give to various actors and they all share the same functions now this adds the ability of very very different actors sharing very similar traits in this case and interaction so I could use the same thing for items signposts goals so forth so open it up and we can aeneas new function interact and click compile and save it so to assign that NPC that interact interface go to the NPC again blueprint editor and you will click on class defaults up here and on the right hand side you'll see and I saw a class setting so clicking across it on the right side then you'll see interfaces and add and you should see your interact interface there as one of the options compiled and that will do for him okey dokey so now we've got that we now need to be able to tell our player to interact with the NPC so the way it works is through a line trace which we'll get to in a moment but first let's make a HUD for our player so I'm gonna go make new folder and it's going to be called user interface and in here we go add new user interface widget blueprint call it the heads-up display and open it up so the heads-up display here and we leave blank for now we come back to that in a moment and let's just add it to the screen first of all so to do that I'm gonna go into my third person game mode open food editor begin play we're going to create a widget and I choose the heads-up display promote that to available and and it to people so hopefully you watch the first tutorial series on dialog systems so a lot of this about that go over again but essentially we just create a widget storing as a reference and then adding it to the viewport so we can actually see it close this and go to our third person character so on my character I'm gonna do first of all I'm going to get reference to that HUD so I'd like to keep casting to it so over here I'm good begin play and white click get my game mode from here cast to my third person game mode and from there I can access that heads-up display variable that we stored at referencing and here I promote to verbal now the benefit of doing this means I have to keep doing a cast every time I want to access the heads-up display because now I've got a reference doherty to it I've got the address for it to it I'm so to speak so play a HUD and like so right so now we've got that we now need to do the interact check in so to do that I'm gonna make a function so new function and I go call it interact check and compile and this thing's gonna be called in two locations first of all I'm gonna look at the impacts let's move forward and put onto there now this means it'll trigger all the time because move forward like a tick event it keeps going all the time it will need to return one or zero based on well not you actually are moving so inter always happen says always can we check in if we have interaction available to us and also going to do an interactive key so we're not interact with the actual MPC something all happen so do that let's go to edit project settings and go to input and add a new action mapping hitting a little plus arrow and call it interact use a key on my keyboard and leave a lot so so now if I type in interact I'll get the action event interact and never do an in fact check right at the start of it so let's go to the interact check function so as I said this happens for a trace okay so I'm gonna do a line trace or severe trace you can do either I'm gonna do a severe trace personally know it's a sphere trace by Channel I mean your start location and location and a radius primarily okay so first of all let's get start location so the start location is going to be the player characters location so please simply just get actor location and plug that into the start value there and next we need to get the rotation that direction to play its facing so we want to get a certain distance away from the player but to check from so we're going to get the dude let's do get active rotation now you could do either camera or actor put in a third person template their camera can move independently from the character so you can have either one I'm gonna do actor for now but you can have camera if you wish so once you've got in rotation we need to get the forward vector and that gives you the direction they're facing in okay and then from there we can multiply this vector by float and this is the length of how long we want to check for so it's a bit of deranged of the check so here I want to put in about 200 and I'm gonna add that on to my actor location to get our end radius I'm gonna change that to 25 and my choice channel I'm going to change to camera and for purpose of testing I'm gonna change the draw debugger type to one phone click compile now if I were to play this game you'll see the sphere trace is popping out the player okay but if you've moved come around it's not connected to them okay so if I let's show you a difference of that probably using a camera location so if I go camera get rotation and plug that in instead you it's hard to see because it is facing exactly where the camera is going but it's actually rotating to match where the camera is facing but move quick enough maybe you can see it you can see it when I'm carding with the floor go green that means that is interacting with something okay so you can use either - fine okay so I'm just going to leave that as is for now to save time okay so after you sphere trace will have an out hit okay and from the out hit we need to store what we are hitting with okay so right click on out here and choose split struck tap in to get all the blades off on our sphere trace one of those is the out hit hit actor this is the actor that we are hitting with a sphere trace I want to promote that to a verbal I see you just do am branch first make sure we got blocking hit and if that's true we're gonna promote that to a variable a local bevel let's don't do that promote to local rebel and interact Hector and I will plug that into truth okay so if it's true the interact actor is going to true asset to this this actor has come out the hit me going to store as a reference it all actually in fact I should check whether she has an interface the interact interface so before we get to there just hop in interface you'll see does implement interface that's one of the options and that would be branch around so oh and change your interface to choose your interact interface there we go okay so if it's true interface actor interact actor will be set to whatever we're hitting if it holds the its fact interface so let's just test that out I'm gonna do a print string and drag that into there to get display name so if I interact with the world it's shown it shouldn't print anything because none of this stuff holds that interact interface but if I put my MPC in the world like so it should now print there you go so Bab it's working okay we've got that MPC being detected my third person character so I'm given our print stream check because we know it works so the next job is to make it display a notification on the screen the way we display in that fashion on the screen it's going to be handled all by our heads up display so open up your heads up display which is just a blank canvas for now and go to its graph and top right we're going to create a function so add new function and we're gonna show you make it say display message and this thing's gonna hold two inputs okay good one of them it's going to be the actor it can be a type of actor another one it's going to be a boolean called show message okay and click compile okay so for the show message we're going to put it into a boolean and if it's true we'll make it display message if it's false we want to remove the message okay so let's first of all create a widget for our notification so over here I'm going to make it add new widget interact message okay so do a basic one I'm just gonna delete the cameras panel we don't need that I'm just going to put in a border actually on first size box around that border right click wrap with size box and I'm gonna give it a width and height override I do a height override not high override minimum do minimum reduce 300 by 100 change the to desired so I can see we're looking at here okay so on the border you must like that and I'm going to change the background of it so on the appearance we've got brush and brush color change the brush color to whatever you like like so I'm just gonna store that up here if you directly color by the way up here you'll store it as a swatch for later so you can use it for other UI elements so it's a bit of time and I'm gonna put some text inside my border which I'm going to Center and center okay okay and so text audience by here and we got the McGrath make a new verbal and call it message text and that's going to be a text value and your eternally what I / one okay so we can access it from elsewhere default value that bomb I'm going to say press e to interact compare that go back to your designer and with the text selected go to where says content and you'll see a bind button choose that and you can now choose your message text so this text will now display whatever that verbals display does compile this and we can close it okay so back on to our display message function on our heads up display if it's true we're gonna show message we want to right click create widget anyone choose that interact message we just made them oh sorry you want to go if we go back to our inter message go to your graph click on message text and you'll expose on spawn compile it and now you'll be able to access that text seeing you'd change it to wherever you like okay so on the in fact message widget we do this and then I'm going to store this as a variable yeah new moveable message widget and I want now to add this to the canvas so you can see it on the screen so go back to the designer click on your canvas panel and you will go up to the top right wisss is variable tick this and then it changes to HUD canvas and back to our graph so and I could see my hot canvas as an option in my variables list I can drag this out choose get and then from there I can add a child to it add child to canvas plug that all you like so now you added it to the canvas we want to set some percent of it so it's positioning and its size and things like that so I'm gonna go set size set auto size anywhere tick that is true then we want to set position and this one is gonna be a bit different okay so to keep it next to my location I'm going to get the location of the act I have got here actor and scroll down to bottom get actor get location actor location and there's a node that you can do and you get typing screen you'll see project well - screen and that will take a weld position of actor and give you the screen coordinates of in a 2d space so plug that into your canvas in position you'll need to apply a controller because you need to know is which viewport is looking at so get player controller there and click compile so it's the the most work it's doing what we now need to do as style is check whether or not we've actually already got the message up if we have we don't want to create another one we just created them so drag your message widget verbal out and choose get right-click on it and go converted by a day to get plugboard us in if it's not valid we'll go to the crate widget so if that makes sense if you don't have it it's going to create one if you do have it it's not going to do nothing it's just going to drop in to nothing okay so what about removing it so show message is false we're going to come off this branch here and we want to remove that message widget from the canvas so drag your message widget out just get and then from here you wanna go remove from parent plug that into force drag the message widget out again and you set and you leave it as blank okay compile and let's go back to our third person character so a third person character has this interact check going on and once we've set the variable for interactive actor we now need to call that heads-up display up now already got the heads-up display HUD here I can drag this out and choose get and then from there I should be able to just call my display message function play that there choose so message the interact actor will go into actor just compile and let's see if this works there you go it won't go away yet we've done that bit but it pops up on the screen so go back to your player character and what you do is do the same thing again copy and paste that display message out like so the target being a player's hunt and what we wanna do is turn off show message and that will now hide it when we connect this up to this force here and also this force here so now if I'm not looking at anything with an interacted you'll disappear there you go so there's the interact message we now need to make it when we push Ichi to display our dialog box so it's been quite a long video hopefully the next one to be a bit shorter trying to get this one out of the way so it could focus on the actual dialogue system itself in the next few episodes so thanks very much for watching you have any comments or questions you want to know about the system please leave them below in the comment box and I'll get back to them if I can if I support me and see the next episode right now we head over to patreon calm for slash wine laylee big shout out and thank you to Alex who's been supporting me so far massively this this past month thank you very much and thank to all my patrons really thank you everyone for supporting me it can be just about you guys so thanks very much and I'll see you guys next time bye bye what hold up we had an error before I crashed not crashed it just came up load warning messages it's because this thing may not exist all the time so to right-click on that and choose that to buy they'd get and plug that into its valid there and force there and now solve that warning issue you would have had if you were following along with me just then let's just check that no one messages excellent okay Cheers see you guys next time bye bye [Music]
Info
Channel: Ryan Laley
Views: 62,505
Rating: undefined out of 5
Keywords: Unreal Engine 4, UE4, How to, Explained, Dialogue, Dialogue Tree, Behaviour Tree, Questions, How totalk to NPC, How to show interact message, Interaction, notification, message, interface, UI, HUD
Id: 3uW7CgmrKAo
Channel Id: undefined
Length: 24min 41sec (1481 seconds)
Published: Thu Jul 04 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.