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...
The best part of being a game dev to me is...well, making games. So much can be done without touching a line of code, which is great. Well, not really. Recently, I have made sure to implement more code (C++ and C#) into my projects but I feel like I'm neglecting my programming. So I decided to boot up some exercises and test myself with creating a cash machine/ATM interaction system in C++. The first step was to set up the functions and then define the variables. I then created the UI and printed out what would be the interface and then allowed the user to input their choice. I wrapped that in a do while loop and created switch cases for each choice presented in the UI. I then initialised the functions for later use. Then the output presents the user with the choices for input. (Yes every option is 1 in the UI for now, don't worry I catch that error later!) If the user presses 4, they will exit the interaction. To show the balance, I printed out the balance and added a setpre...
Comments
Post a Comment