Posted March 27, 2025 by Indifferent Kitchen Std.
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.
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.
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.
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.