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.
(This post follows on from this page: https://triplehitcombo.blogspot.com/2024/07/remaking-mario-in-unreal-engine-5-part-1.html ) Last time we left off, we ended on the UI and ensuring that all variables to be displayed on screen worked as intended. Checkpoints First, I made a checkpoint system to give the player a place in the level to return to, to avoid frustration if they repeatedly die. The concept was to make the visual representation for the checkpoint, then a trigger volume. In the event graph, I started to work on the blueprints. The beginning of the code was a cast to the player and game mode BP. Then a setter for the spawn transform for the rotation of the checkpoint. This was set to a Do Once loop that connected to a timeline to display the animation of the flag changing when Mario enters the collision. Since the checkpoint can only be triggered once, a Do Once loop was the most useful choice. After the timeline was set a lerp was added to adjust the rotati...
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...
Comments
Post a Comment