What is the best way to use a dialogue system with an NPC?

Hey guys,

what would be the best start for a Dialogsystem with an NPC?

My NPC should have the following:

If it’s a normal NPC it should just have a Talking bubble if you “use” him.
If it’s an important NPC (Vendor,Quest) with more dialog i want the HUD to display the text and option for the player to choose.

I know how to use all the things to create this, but i want to know what would be the best way to make it easily changable. So that i only have one NPC Blueprint where i can setup the NPC to be something from above.
The NPC or important NPC difference would be with a simple boolean or an enum.
But what about making the Text and answer options?

I thought about arrays that have the possible Text Lines and Options in them (one array for text, one array for options), and on pressing the hitbox auf the options i would change the text to the next array index matching the hitboxname (it would be a number), but how can i change the Options?

I would have to save the count of the options and go through the array with a loop that has specific start and end indices…
That would be tricky to save and not so easily changeable.

Im think about an easy way to make this:

NPC has “this” as default opening text and 1 or more options to choose for the player.
If the player presses a hitbox, a new text will appear with new options that have new “function”
to change the next text or maybe leave the conversation.

Gnah, hard to explain in english >.< I just don’t want to set something up that is hard to change for every NPC that has different Texts etc.

Hi ,

I have a potential solution for you that allows you to assign multiple strings of text to an actor and cycle through them. What you can do is set text variables in an array, and use the length of the array + 1 to cycle through this array. Put that +1 into the counter of a “do N” node to accomplish this. Plug all of this into a set text (or equivalent depending on how you are setting up your text for this). Plug a get array node for the text array into an append string and then attach the output of the append string to the set text node. To reset I used a custom event at the end of the chain that resets the counter if the counter is equal to the array length. To determine which npc you are interacting with you can enable/disable the player input based on proximity. I used a box volume to accomplish this though there are, of course, other options available. The great thing about this setup is you can have multiple actors with the same parent with completely editable variables for the text! This allows you to set exactly what phrases you want each NPC to have. Have a look at my image below, I’m more than happy to explain any part of it that doesn’t make much sense!

1 Like

First of all, thanks for the answer (:

I don’t know how the Do N exactly works.

It counts from 1 to N so we are using length + 1, but isnt length giving the number of items back? So we are going out of bounce if we add 1 here, or?

But i get the idea. The question about Do N is: Is it counting like a loop or only adding 1 if i press R. So i need to press R N-1 Times to get through all N Texts?

My problem here is that i go through the array linear (i hope thats the word for the thing i mean), but i want to assign strings to the Textarray depending on what answer the player clicked.

For example we got the following:

Player talks to NPCs:

Hey, what can i do for you?
1 - Tell me about this city.
2 - Tell me about yourself.
3 - Nothing, bye.

So, if i press the first Hitbox(text), i want to get the text about the city
and if i press the second one, i want to get the text about himself.

I know i could realize this with giving the hitboxes single numbers as names and just change the Get Index to the clicked hitbox name.

The problem is: I want to also change the Options and sometimes the number of options.

So lets got further. Lets say i clicked the first buttons (Hitboxname 1)
and i get the text of index 1 out of the text array. Now i want to have different options like

Do you realy want to hear something about that boring city?
1- Yes please!
2 - No thanks!

So with pressing the first option now, i want to get to the 4th field of the text array (first is Standard text, second is cityquestion text, third is text about himself, 4th is the real city text)
And the sencond options should bring me back to the first field.

But how can i update my options so that i dont have to change them all manually for each NPC?

I hope thats clearer now (: Your solution is a step towards that and i hope you know a way to extend this, because i dont know how to solve this.

So, hey ,

i thought about your method and tried to work backwards to a result that i could use for my system-in-mind.

The outcome is this:


So now i use 2 Structs and some Arrays.

The first struct i use is a struct of a

  • String Array for multiple Textlines of the NPC (is there another way to realize multiplelines?)
  • Array of the second struct, the Options.

The struct Options also contains a string (could be an array if the options needs a linebreak) and it contains an int value for the next index of an array that is of the first struct type.
So i have an array that contains a dialogtext and options per index.
I don’t know if i could read the text from outside (like a datatable or something) but for the moment its the same amount of work to write it in the gaps, so i’m good with how it is right now.

If you have some additional thoughts on this i would be happy.

(: Thanks again for your inspiration!

This is brilliant! I am going to keep playing with it in my (albeit limited) spare time to see if I can add onto your idea! I also look forward to seeing what you come up with using this dialogue option.

Hey , I know it has been a long time since you asked this question, but if you’re still having a problem I am developing a Dynamic Conversation System so all you have to do is type in what you want the NPC to say and what the Character can say and the BP does the rest! (There are a few things you have to do to the text to make it work, but it’s only in the text you don’t need to touch the BP!)

It is very complicated however, and I am still working on it because if I work on it for too long it starts to hurt my head! Right now you can only have 4 boxes of text that appear on the screen in a HUD widget, I am trying to increase that number, but if I add too many boxes the NPC and Character text sections could overlap/go off screen, also if the text is too long it will get cut off, and the way I have it set up (I use a scale widget to dynamically scale the text size) the wrap text function does not work (scaling takes precedence over wrapping, which I think should be changed.) but if you were to set it up as a bubble above the NPC you could essentially make it as large as you wanted! (Until it hits a wall or something)

So, if you are still working on this and still need some help, I could either send you a link of a video I could make explaining how my BP works (The BP will be on the screen) or I could try to section the BP up and comment everything then put some pictures of it in this post if you don’t want to listen to me ramble on how my BP works! (This would probably be faster for me, but it may not be as explanatory as a video, your choice!)

If you have any questions just ask! Also, one last thing, I am currently working on making the text split into multiple sections if it goes over a set character amount (So it won’t be cut off) and if there are too many boxes it will set up the NPC’s conversation into a story like function, so that you will have to click a NEXT button for the rest of it to show up on screen!

I hope this will help you!

Something I did on my inventory/item system might transfer well here too. Give your NPC’s a set of boolean flags, like “isMerchant”, “isQuestGiver”, etc. I used a struct container just to keep them all together. Then, your Begin Play event, you can toggle the properties as needed for the NPC. This becomes easier if you inherent from a parent type. (i.e. you only have to override the stuff you change on individual units instead of setting up the whole thing)

Then, in your dialogue, you can check for these Boolean values and have it pull from an array of lines of texts. For example, your merchants might have an array of texts with different types of sales pitches that could be selected randomly so that there is some slight variation with each interaction. Setting up which array of options NPC’s would use can be offloaded into a very few reusable functions.

(: Yeah that would be a good thing, but i think this can be realized by creating childclasses alone. As long as i have a point where i cast the NPC to its child class, i know what NPC Type he is.

For setting him up i would just need to have the important variables in the childclass und the ones every NPC has in the parent class. So i don’t really need the bools.

But i don’t want to say that you can’t use the bools. (: As long as your system works, it’s good.

I can’t say much atm because i paused the project due to multiplayer problems and time issues.

Still thanks for the answer, got the question on bookmark (:

Hey, thanks for the long answer. (:

I’m not working at this project at the moment, because i had issues with the C++ multiplayer and steam.

I’m happy that you want to spend so much time explaining me your system and i’m really interested, since i love to play around with such things.

But could you imagine doing this kind of “tutorial” for everyone?
I guess a bunch of people would like to know this, since a big amount of users are beginners on logical programming.

If you find the time to create a tutorials (written or recorded), you could post it here:


So not only me would learn from this (:

Thanks in advance!

PS: Keep in mind that different games need different conversation systems. One is an MMO and the other is for example the oldschool button smash Legend of Zelda Owl :smiley:

So if you really make a tutorial, don’t forget to point out the parts that can be changed for the other users (and me of course) so we have our own system :smiley:

But could you imagine doing this kind of “tutorial” for everyone? I guess a bunch of people would like to know this, since a big amount of users are beginners on logical programming.

That is very true! I might just make a tutorial of my BP, but I probably won’t make a video unless some people are still having trouble understanding it or something.

As for the different conversation systems, I will probably use dragable windows so you can position the conversation where ever you want, or if you want it as a bubble above the NPC (or anywhere not in your HUD) I could say a few things about how someone might do that!

Also, as said, I will definitely need to add some options for a “Merchant” or Quest Giver" since I will need those anyways (I could even add the Randomizer for the Merchant or even the Quest Giver, all you need to do is add the text and possibly some weights if you want one thing to show up more)!

I will definitely point out the key parts that could be changed when you need them, I will also point out any laziness on my part where instead of optimizing a section it I left it as is since it works!

When I’ done making the Tutorial post, I’ll put a link of it in here! But if you want to go ahead and get started here is the link to my DropBox folder containing all of the pictures of the BPs (there are 2, the NPC and the HUD, together they make the conversation BP) (the HUD&Examples folder shows you what it will look like and how the Widgets are made)
I of course will explain them all in detail in the actual tutorial, but the pictures are still good by themselves!

I will have a look at the final result (: I have no time at the moment.

But really thanks for that! I will stay tuned.

Hey I am just starting project where dialogue with a few options will be needed and I am begginer, so I"m interested if you made tutorial or if you have some pictures of BP because dropbox link is no longer valid.

Sure thing, here is a link to the wiki page tutorial, and in there is a link to video tutorials! (I would suggest watching the vids first, wiki is old, and harder to understand :slight_smile: Link

If you have any questions, feel free to message me on the forums!