UE5 | Ultimate Dialogue System - Tutorial - Pt1

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hello so it's Michael here and today I thought I would go and give you a quick demonstration of a dialogue system that I've been working on and I'm going to go ahead and actually create a tutorial as well so uh stay tuned for that at the end uh so in terms of the master Mage if we go ahead and talked to him first uh you can see he's got different dialogue and depending on the options that you choose that will affect the dialogue that pops up uh so to give you some items all the items is requested then you spawn some items in there we have poppy here who has a bit more of a complicated sort of structure to section here where you've got different options so if you choose that I'm not sure whatever she's asking it closes out some options where It'll ask you if you're sure or not um so it's quite a quite dynamic sort of option really um and depending on the options that you've chosen so it affects what uh cues are spawned above Poppy's head we then have the keep over here who is wanting to ask you some questions uh to allow you through a particular gate and depending on the sort of answers that you answer with uh it sort of determines whether or not to get them correct or whether or not it lets you come through but he also has a sort of interesting setup where he remembers that you've already he's already asked to ask you the questions once before so it kind of gives you a bit of a slightly different introduction to so the conversation as it were if you're able to get all the questions correct um I think yet again it sort of keeps track of all that and then we talk to him again he remembers that you've completed all the questions but the answer so the dialogue that he gives you is a little bit more randomized in terms of what he what he gives gives you um so yeah so this is kind of like the the dialogue system in a sense um so it is all entirely blueprint based and it's well personally I think it's very intuitive to go ahead and settle dialogue using it so in this particular example I had to have three dialogues that have been set up for the three characters uh that all use the specific base dialogue component as an example uh if we go go into the doorkeeper this is kind of how the dialogue would would sort of look so you can kind of see the flow of the conversation and this kind of controls all the questions and things like that and the options that the players presented with so you've got quite a lot of flexibility in terms of how you choose to set it up to get the dialogue to show that you know in the order that you want it to um but it's super simple and easy to set that up so if I quickly load up the poppy as well and I'll look at their dialogue so this is uh Poppy's dialogue so if you look at zero that's kind of the main one uh you can sort of see how it branches depending on the options they're chosen some of the options clear the progress and kind of reset the conversation sense and others others don't um so yes there's quite a few different you know in terms of the way you can set it up it's obviously quite vast but gives you a lot of control in terms of setting up a dialogue system of course if you love your data tables you might not like the system but if you prefer things to to look visually like a little bit more of a flow graph then this is probably right down your alley and if you are working on a dialogue or conversation system and then this is probably going to be something you probably would absolutely love particularly if you've got quite a lot of characters you need to set up dialogue for and things like that um so yeah so what I'll do is I'll go ahead and just create a brand new project for you based on the third person template just so we're both so we're all on the same sort of starting places it were so I'll be back in a second okay so we're here now in a new project so this is just based on the third person template so this will give us access to the uh the movement character so you can move around and do some things so the first thing we want to do is go ahead and open up the content browser so I'm just going to Doc mine and go ahead and create a new folder under the contents a folder I'm just going to call this blueprints in here the first I'm going to do is create a an enumeration so I'm going to call that enum progress dialogue click dialog state go ahead and open that up we want to add two enumerators so the first one is going to be called pass through and then the second one is going to be called updated so we'll be using those shortly so you can save that out and then close it so the next thing we want to go ahead and do is actually create the base component is it worth it would it would kind of be the base of all all the dialogue that you have happen so in this particular example I'm going to be doing it as an actor component and what that is uh I'm just going to go ahead and open up the third person character so on the right hand side on the components list these are all Active Components like the character movement for example is a an active component and obviously got quite a lot in in here already that you can sort of choose from so we're going to be creating our own active component as like a base that we can create other dialogue from that we can then just add 20 any actor that we wanted to depending on so the needs of your project you can get away doing it as a just an object or even just as a sort of a base actor blueprint if you wanted to of course there are limitations to all of those so I'm going to go too much detail with that um but for this example now we're going to go back to the blueprints folder and right click and blueprint curse and then you just want to select the actor components from the list I'm going to call this uh AC underscore dialog UE I'll just call base so as a as an example if we're starting to go back into the third person character you'd then be able to add that under here the dialog base generally it's not the base one you would use you'd create a child of that and add that one instead so with that done let's go ahead and open up the dialog base component I'm just going to start by removing the two nodes in the event graph uh so what I'm going to do first is just create some of the sort of functions and the variables that we'll need in here to get this all set up so the first function and call that one open conversation uh so it says these functions will will be going back into them shortly and we'll get those set up so the next one is going to be close conversation so we have another one that's going to be called progress dialog and another one which is dialog itself so when you make any child blueprints the dialogue would be a place inside the dialog function so you would override this particular function and then place your dialog in there let's also show you that we'll get to it and the next function is going to be add dialog and then another one which is going to be update selected option we need let's do it three more so this first one's gonna be clear dialogue progress and let's remove dialog progress and then the last one is going to be set dialog tree index okay so that's the function setup so we're gonna go ahead and then just set up the or sorry add the variables so the first variable what I add is called dialog progress so for this it needs to be a type integer this is a map the second option is an integer as well so it'll look like this so in this little drop down in the middle choose map and then for both types they both need to be an integer so the dialogue Pro progress is kind of where it is within uh sort of the dialogue tree as it were um so the first one is the the actual bit of dialogue that it's gotten to and then the second one is the option that the player has chosen for that specific option if there's only one option then it will just be zero if the multiple options then it'll be whichever option to pick so whether it's option three option four that type of thing so the next one want to choose is so the next one to add even is called a dialogue index and this just needs to be a single integer volume so this particular variable will be used to actually keep track of where it is in the dialogue itself the next variable is going to be called dialogue tree index so with the dialog itself because you can assemble it essentially like a tree like things that Branch out you can have multiple starting branches so you can kind of like toggle these depending on certain events in the world whether it's you know a shopkeeper for example they could have one particular tree of conversation to go through if they've got no stock and another one they go through if they do have stock and that can kind of change uh what happens the next variable that we do need is a reference to a widget uh however we don't have that widget yet so I'm just going to quickly go ahead and create that widget as well so in the content browser it's kind of a new folder I should call this UI and then in that folder just come down to right click user interface and then widget blueprint and you want to select the user widget option I'm going to call this a w underscore dialog like so and then just make sure that saved we'll come back in and actually populate that shortly so if you go back to the actor component the dialog base and then we can go ahead and create that reference so it's going to be a dialogue widget and then for the variable type that's going to be the widget that we've just created and that's gonna be an object reference so we can saving compiler I'm just going to move that widget reference up a little bit so obviously you can order these however you like okay so with that done want to go ahead and start filling out some of these uh functions so the first one is going to be the open conversation so we'll start with that one so when we first open the conversation what we want to do is actually create the widget with the dialog in it so we're going to create a widget and then for the attack you want to choose the widget dialog that we just created what we can then do is pull in your dialog widget and want to set the reference in there to the one we've just created and then want to go ahead and add to viewport um once we've done that we then actually want to progress the dialog so so in essence it updates the first thing in the tree so we'll just add that in there it should make a bit more sense when we actually populate that um but we'll just hit that on the end for now so another thing we do need to do is actually provide the widget with a reference to this active component as it were so anything that happens within the widget it can communicate back to this particular so what we can do if we browse back to the dialog widget I just want to go ahead and open that up in the event graph just delete these for now under the variables we just want to create a new reference and we can call this one owning dialog component and for the variable type we want to do it as the actor dialog base so the AC dialog base like so uh once you've done that you don't want to make sure it's instance editable and we expose that on spawn and then we can compile and save that out so then when we go back to the actor component base on the create dialog widget if we just refresh that node you should then see it pop up um and that's just because we made that exposure spawn so for this particular one we then just want to get a reference to self so that's going to then pass that the reference to this um actor component to the the widget so we can use that in there when we need to okay so let's move on to the next function so that's the close conversation so this is the one that'll actually close the actual uh dialog widget so what we can do is come in here and just remove widget remove so I want to go and choose the remove from parent just like so so in the closed conversation you might want to put some other stuff in here regarding the character so if you disable the character movement when they first open a conversation for example you'll then want to re-enable that movement to but potentially in in here um obviously we'll come back into here later and we'll add something like that when we get a little little dirty setup setup so just to sort of demonstrate that it's it's working okay so uh yes that's that function done it's a fairly very simple so the next one I want to do is the progress dialog so for this particular one what we want to do is pull in the dialog index and we want to set it so the very first thing what to do whenever we progress the dialogue is actually set it to minus one so this will make a bit more sense shortly as we sort of start setting things up a little bit more uh and then once we've done that we then want to call the dialog function so the dialog function is where the dialog itself will be housed so whenever we progress the dialogue we reset the dialog in index and then we kind of go through the tree to see where we're at okay so in terms of the functions so we don't do any to do anything in dialogue we would only set that up in the children so the next thing we want to do is set up the add dialog so if we open that up so when it comes to the add dialog function we do need to add some inputs on the dialog node so these all need to be text so just add those three in there and we'll name them so the first one is going to be the name of the speaker so the name of the NPC um or you could even be I don't know if you've got a sign for example just the name of the sign you know whatever it is that you you want the name of the speaker to be the next one is dialogues this is the actual text yeah the spoken bits that you want and then the final one is the options text so this one also needs to be a be an array so you can update that as well okay so with that done what we can then do is we want to bring in that dialog index again so this is where we would uh also a few moments ago in the progress dialogue it's the same variable and we want to go ahead and add one to it so there is the increment int so that'll always add one to the particular variable so we can add that in there so every time this add dialog button is called it's going to increment that dialog index by by one so if it starts off at -1 when it's first called it makes it zero so then you can start looking at sort of zero dialogue in in the tree that needs to be called so once we've done that we then need to get the dialogue progress and what we need to do in here is find if a piece of dialogue has already been been shown so this is where the dialog index comes in again so at some point during the tutorial we will set up the dialogue progress being being populated but as an example if you have some dialogue that say option zero it's kind of like the first one uh player presses the button which just continue it will then add zero um zero zero into the dialogue progress so if we should quick example say it should look a little bit like this uh it's not let me do it add another one one so so it kind of populating it so then you get to the next one it'll there'll be a one in there uh let's say the chose option like second option in this case let's say it look like that um and so forth and that's kind of how it works so what this is doing is has this option already been shown so what we can then do is if it's found so then this option this bit of dialog's already been shown we can come in and return so in this case this has already been already been done if it hasn't what we then need to do is update some dialog text now this particular function we don't have yet so what we're going to do is go back into the dialog widget and just create a new function I'm going to go ahead and call this update dialog text and you want to go ahead and add four variables to this so the first one is going to be an integer and that's going to be of type dialog index and then the next three are going to be the text values that we need oh usually helps if I press the right one so similar to in here we have speaker dialogue and options text we need the same ones on here so speaker dialog and then options text like so I'm not going to populate this one just yet so we'll come back to that one shortly if we go back to the ACT component what we can then do is get the widget and then call the update dialog text and we can plug that in like so and then it just be it's just a case of connecting these values which can copy the dialog index connect it there and then we need to get these inputs here so you can connect them like this if you wanted to but I like to try and keep things looking a bit tidier so I'm just going to get the reference to the actual input value so you do get say dialogue you want to get the one that's underneath the variables so and then get options text so I'll connect it that way instead so it just looks a little bit tidy that way and then I'll straighten these connections like so and then lastly we can then return on that one again okay so the last thing that I need to do is we need to add a few outputs on on this particular function so the first output we want to do is the set it to the enum that we created earlier on so the enum dialog state and that just needs to be a single variable type and we'll just call that state so with that done um we'll have two return nodes and we just need to set these up so if it comes to the top one so it's already been done then we can do the pass through if it hasn't then we do updated so that particular state will be updated if it's uh if it's actually the text the next output we need is the option index and that needs to be a type integer so what we can do on this one is actually connect from this fine node for the map we can just plug that straight into the option index just like that okay so that is this particular function complete so let's move these over a little bit there we go okay so that's that uh you know done there so this is actually the main a sort of section in regards to the dialogue is itself so when you create children you override the dialog function and then that's where you'll be adding your sub dialogue trees okay so with uh the add dialog function complete we can move on to the update uh selected option so what we actually want to do here is this is where we'll actually add uh values to the dialog progress variable so just drag a copy of that into the blueprint I want to go ahead and add I want to make sure it's the add map version then we can connect so what we don't want to do is add two inputs to this particular function so we'll just drag straight from these two uh and that should just automatically create them quickly straighten these up there we go okay so uh so in terms of the names for these uh particular inputs if you click on the first bit you can edit them on the left hand side so the first one so the one at the top so that's going to be called progress index and then the last one that's going to be the option index so this is where when a particular option button is clicked it will actually call this function and that's how it passes the information back to uh so the base dialog system as it were and that information then gets stored so when it's checking the tree it knows what options have been picked sort of at which point so with that done there the last thing we want to do in here is just call the progress dialog again so this just causes the dialogue tree to progress when an option has been picked by the player so it sort of does that automatically okay so the next function in the list that's the clear dialogue progress so when I go ahead and open that one up and this one's nice and simple all you want to do is just pull in the dialog progress variable and you want to go ahead and call the Clear map function on that one so so whenever this is called it just clears absolutely everything in regards to the dialogue Tree in terms of the options that the player has chosen the next one then is the remove dialog progress so this one allows us to kind of like Backtrack on the dialogue tree a little bit so there might be certain sections where depending on the option that the player chooses you kind of want to loop back to a previous bit within the dialogue tree so the way that we can achieve that is you want to go ahead and add an input to this particular function I'm going to call that progress steps and that's going to be of type integer what I want to do is pull off of the main execution line I'm going to call a for Loop like so and then we'll just connect the progress steps to the last index so the next thing you want to do is pull in a reference to the dialog progress variable again and this time we want to do a remove from that we'll get that straight up to the main Loop body straighten those up and then what we want to do is get the current dialog index and I want to minus or subtract the index of the loop body like so so straighten those up and then we can connect that straight into here let's try to turn that up and that's that particular function done so depending on what the initial progress steps value is that'll determine how many of these get removed based on the current dialog index so the final one we need to do is the set the dialog tree index so go ahead and open that up for this one we do need an another input again uh so this time it's going to be of type integer and I'm going to call this dialogue tree index and then you just go ahead and pull the dialogue tree index in and we're going to go ahead and set it to whatever that input is lastly what we want to do is clear the dialogue progress itself as well so you can call that function into there so that itself is is that function complete as well so the dialogue tree index is kind of what can be used to control different branches within the dialogue conversation so whenever we set this value generally you would you would want to clear the dialog progress so anything that's been done previously it gets cleared out so it's able to sort of flow down the sort of the previous price
Info
Channel: Michael Pattison
Views: 26,092
Rating: undefined out of 5
Keywords: Unreal Engine 5, Dialogue system, NPC interactions, Blueprint scripting, Game development, Game design, Tutorial, Unreal Engine tutorial, Dialogue trees, Non-playable characters, Player choice, Events, Variables, Game programming, Unreal Engine beginner tutorial, Unreal Engine 5 tutorial, Unreal Engine 5 dialogue system, How to make a dialogue system in Unreal Engine 5
Id: 88xikHeYQDA
Channel Id: undefined
Length: 29min 7sec (1747 seconds)
Published: Fri Mar 17 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.