loader image

Dialogue System (Subtitles & Audio) (C#)

A system I wrote that handled dialogues from one or multiple sources, including the UI for subtitles and the audio sources.

Scroll to
View More

mouse

One of the main complexities associated with Dialogues is handling dynamic situations where you want a character to talk at arbitrary player-triggered gameplay moments. Cutscene dialogues, in this sense, are easy, because they are triggered in a sequence and in a predictable manner—gameplay dialogues: not so much.

What if the player runs out of range from the person talking? What if there are two simultaneous dialogues that require the same character to be talking? What if the player pauses the game mid-way through the dialogue?

These were all considerations I had to have. I set out to create a modular Dialogue System for the games I was going to be involved in programming. This system had to support all the above situations; and more: an unlimited number of sources, audio clips, and subtitles; and be modular with all of these so that its reusability would be a no-brainer.

To do this; I divided the logic into two main classes: Monologues and Dialogues. Dialogues are just a conversation between two or more characters. Monologues are like individual voice lines. Hence, logically, a Dialogue was made up of one or multiple Monologues. Dialogues could easily be triggered using a key-value pair and a Dictionary; I took full advantage of the Unity Event system to create modular gameplay instances that could trigger different goals. Killing your first enemy? or three enemies? Finishing an objective? Going through a new area? Picking up an item? All of these could easily trigger a Dialogue.

You can see this Dialogue System in action in ISS a and Before Dusk games I have published.