Designing a Dialogue System Concepts ¶
Introduction¶
States and transitions can be extended to support customized dialogue systems.
The Example Project has a dialogue map which shows one possible system using an open source Dialogue Plugin for Logic Driver.
There are many ways you could implement a dialogue system. Logic Driver 2.0 provides the basic essentials but the end implementation is up to you and what fits your game best.
For this guide the Dialogue Plugin will be used as an example, but it's possible to create a system entirely in Blueprints without using C++.
Overview¶
There are some key components to designing a dialogue system:
- A
state class
which handles reading text and deciding what to do with it. In the dialogue example project it pushes the text to a global system stored in the GameMode which then hands it off to the UI.- TextGraphProperties which should be added to your state node class. This supports easily formatting text with variables.
- Speaker(s) to represent who is talking. In our plugin it is an object type and represents a single speaker.
- TextGraphProperties which should be added to your state node class. This supports easily formatting text with variables.
- A
transition class
which decides when a node should exit such as from user input. The global system in the game mode may want to handle that, and the transition just read from there. - Another state class which represents a choice if you want to provide multiple options to the player.
Manually Navigating States and Transitions¶
You might run into the need to find out which nodes come next or if a transition can evaluate. That is much easier to do in 2.0 as you can have direct access to node instances within Blueprints.
Example: Discovering Choices¶
Let's say you're at a node that has several choice nodes coming out of it. Our initial goal isn't to switch states to the choice, but instead determine if the choice should be displayed to the user or not.
We don't want transitions to evaluate and switch states like they would normally, so it would be a good idea to have the transition class recognize when connecting to a choice
node and not do anything, or just have the transition class set to not allow evaluation by default and leave it up to the dialogue state class
which leads to the choice to handle it.
GetOutgoingTransitions¶
State nodes can call GetOutgoingTransitions to retrieve all connected transitions. Each transition has access to its connected state so you could look and see if you're connecting to a choice node or not.
What the dialogue plugin does in this case is manually iterate all transitions, enable evaluation for each one by calling SetCanEvaluate and checks if the CanEnterTransition
method is true. Then sets evaluation to false after. If a transition passes it means the choice is allowed to be displayed. This information is then sent to the GameMode which is sent to the UI to display choices to the user.
SwitchToLinkedState¶
States can also call SwitchToLinkedState which forcibly moves the node to a connected state. In the dialogue example the state node owning the choice will switch to the choice node only when selected by the user. Then On State End of the choice node knows to end the dialogue sequence if applicable.
Behavior¶
It will be beneficial to define behavior for your nodes. Dialogue transitions can be automatically placed when leaving a dialogue node and you can limit dialogue choices to only be selectable from dialogue nodes.
Closing¶
This guide is just a way to help get started with some concepts and will likely be expanded upon further. If you have questions please drop by the Discord Server or Forums.