Implementing the Dialogue System
Hello! I am Nikole Chua, the primary UI programmer for Relic of the Hollow King!
Last week was about implementing functionality for the settings menu of the game. This week I focused on implementing a dialogue system that will be used in our game. The dialogue system will be used to tell the player about important objectives that they should focus on, tell them when they've collected an important item, or just to give the game's world some flavor by having interactable NPCs.
Before I actually started programming the dialogue system, I made some pseudocode to figure out how I wanted the dialogue system to work. The following images are my pseudocode for the DialogueComponent and an implied DialogueInterface.
This pseudocode, of course, was not perfect and some parts of it had to be moved or edited when I actually started coding it, but putting it this way helped visualize how I wanted the dialogue system to work.
I chose a DialogueComponent rather than an abstract NPC class because I figured we would want to be able to attach the dialogue system to items as well. We already have BasePickup and BaseCharacter classes so it felt redundant to make copies of those just for the dialogue system. The DialogueInterface was made so that the player can determine what is something that has the dialogue system attached to it. Interactables/Actors with the dialogue system will have a collider that the player can overlap with. When the player presses the interact keybind, it will search all overlapping actors and see if any of them have the DialogueInterface. If they do, the player will call PromptDialogue() from the interface. Interactables then override this PromptDialogue() function from the interface with the Talk() function from their DialogueComponent as shown from the pseudocode above.
The HandleInteract() function in BasePlayer. This function is bound to the interact keybind (which is currently "F"). As is shown, the player will get all actors that is currently overlapping it and then see if any of them have the DialogueInterface, and then calling PromptDialogue() if so.
Due to how I made my pseudocode, translating it to actual code was fairly easy. When I came around to testing it though, I ran into the issue that my dialogue box wasn't being made and it caused the game to crash due to being unable to call functions from something that doesn't exist. However, this was easily solved by just creating the DialogueBox widget in BeginPlay of the DialogueComponent rather than in its constructor.
This is BeginPlay() in the DialogueComponent. If the DialogueBox fails to be made, then the DialogueComponent will destroy its owner. Otherwise, it'll call the SwitchDialogueBox() function from the DialogueBox widget which changes which dialogue box it's currently using as the dialogue box handles both special item and NPC dialogue.
After I solved this issue, the dialogue system worked pretty well with minor problem. Below is our player talking to our example NPC, Oddly Self-Aware NPC.
A demonstration of the dialogue system in the game. Apologies for the low quality, you can only do so much with a max filesize of 3 MB for uploads. At least the dialogue box is legible enough to show it off. As you can see the text scrolls and there is small arrow animation/prompt once the NPC is done speaking. It is not shown here, but you can also skip the dialogue instead of waiting for the NPC to finish speaking.
Relic of the Hollow King
Status | In development |
Author | Indifferent Kitchen Std. |
Genre | Action |
More posts
- Experience systems and bug extermination.5 days ago
- What it's like when a player won't look where you want him to.30 days ago
- Too Much or Too Little? Lighting31 days ago
- Implementing Audio & Video Settings32 days ago
- The Fight Between Movement and Magic37 days ago
- Friend or Foe? Problems with the Generic Team ID37 days ago
- Material and Sound Challenges37 days ago
- Sword & Shield37 days ago
- Implementing the UI38 days ago