Creating a simple dialogue system in Unreal Engine 5

 Through my early days as a gamedev, I've learned a plethora of neat techniques but there was one that I always wanted to know how to do. A dialogue system. Here is my first attempt at a rudimentary system. This will be redone very soon with more depth.

The very first step was to create a interface for Dialogue. Then a duplicated the Third Person Character blueprint and changed the meshes for both. 

I made variables for this NPC, the first being an array variant of the string variable. This was give as many options for dialogue as I wanted. Then I created an index variable as an integer to determine in what order the dialogue was spoken. Then a reference to a widget was made.

For the string array, I added three elements and added three simple sentences.


The Index integer was initialized at -1. This was because the first element of the array began at 0 and the way the code works, we are incrementing the index. Starting it at -1 means we start blank, then move index 0 (the first sentence). 



To start, I got the index and incremented it and attached this to a branch node. The condition was that the array needed to be less than the index. This meant that if the branch was false and it was less than the array length, the widget that displays the text is removed. If it is true, we check to see if the UI is valid and if it isn't a widget is created and the text is set this loops and constantly checks if it is valid or not. Basically, we approach the character, try to talk to them and we see if the array length is above -1 and display 0-1-2. Then we go back and run the code again.


And in the player blueprint, the code is simple. I check to see if the player is overlapping with the NPC and see if that NPC has the interface we made and if it does, we execute the talk function. 


Creating the UI was simple. First, I created the visuals, which is just a text box with a blur behind it.


And under "Content" this element is bound to an event, which you will see called earlier!


And that's it! It's really rudimentary but works for simple characters in the game world. More can be done here, disabling player input, changing camera location or having the dialogue pop up like small text boxes are all simple changes that can really amplify even this basic system.

Here is a short video of the system in action. 





Comments

Popular posts from this blog

Remaking Mario in Unreal Engine 5 (Part 2)

Remaking Mario in Unreal Engine 5 (Part 1)