Creating a simple dialogue system in Unreal Engine 5
Get link
Facebook
X
Pinterest
Email
Other Apps
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.
For this project, I aim to remake Mario (or at least as best as I can) in UE5. The project makes sense as, while it is simple, there are a lot of core concepts that are valuable for any newbie game dev. Here is the first part of what I've done so far, which is a lot of set up. Stay tuned for Part 2 soon! The first port of call was to get the camera in position to act as a side scroller. Here I set parameters, to allow for customization of where the camera goes in real time. This allowed me to find a sweet spot that looked good for the perspective I wanted. (This ended up looking similar to this) The next step was to set snap layers. This allowed me to set layers for placing assets for the foreground, main play layer and background. This is important because all of the interactable objects would only be in the middle of the play area and without the snap layers, if they were incorrectly placed, the player may not be able to interact with them. (The snap layer sett...
Continuing my (almost) daily C++ practice, I am now making a program to check if a credit number is valid or not. The first step was to use the Luhn algorithm, researching this, I learned it was a simple and effective fraud protection algorithm. I broke in down into a few simple steps using this formula and got some test credit card numbers online and attempted the math. It took a little while to get used to, but I got used to it quickly enough. Naturally doing the math is tedious, so I took to Visual Studio 2022 and booted up a C++ file. At first, I created some functions to use later. These were for getting the digits and the sum of the odd and even numbers. Then I created some declarations for each of the functions. I then added some functionality to the main code, mainly prompting the user to input their number and allowing them to do so. Then as a result, adding the sum of the odd and even digits together. For the sum of the even digits, I created a for loop and as I wa...
Comments
Post a Comment