Working With the Graph

The only reasons you'd want to work with the dialogue graph is if you'd like change the graph itself, create your own dialogue window, or update the existing dialogue window. However, there's no simple method at the time.

Getting Nodes

To change any data in a dialogue graph, you would have to access the nodes. You can get the full list of nodes with the DialogueGraph.nodes field.

Getting and Converting

To get a specific node by ID, you can do the following:

// graph is a DialogueGraph
QTNode node = graph.nodes["node id"];

The QTNode class is a base class for all nodes. You will have to convert the node to a specific type before working with it.

// Convert to dialogue node
var dialogueNode = node as QTDialogueNode;

// Convert to choices node
var choicesNode = node as QTChoiceseNode;

// Convert to receive node
var receiveNode = node as QTReceiveNode;

// Convert to complete node
var completeNode = node as QTCompleteNode;

// Convert to trigger node
var triggerNode = node as QTTriggerNode;

// Convert to boolean node
var booleanNode = node as QTBooleanNode;

Getting the Next Node

To follow the correct dialogue node order, you can use the GetNextNode method. This method will start the dialogue graph at the initial node. Behind the scenes, the dialogue graph will set the returned node as the current node. So, you can get the next node through connections whenever the method is called again.

var currentNode = graph.GetNextNode();

// If the previous node was a choices node, you can get the next node
// by providing a selected option key
var currentNode = graph.GetNextNode("selected option key");

Getting the Next Node Without Setting as Current

If you'd like to get the next node without setting it as the current node, use GetNextNodeWithoutChange.

// The currentNode is the node to start with when trying to get the next node
var nextNode = graph.GetNextNodeWithoutChange();

// If the previous node was a choices node, you can get the next node
// by providing a selected option key
var currentNode = graph.GetNextNodeWithoutChange(currentNode, "selected option key");

Creating Nodes

Creating a node will differ slightly for each node type, but the pattern is the same.

Example

Here's an example of how you can create a dialogue node with a connections to other nodes.

// Generate a node ID
string id = QTUtility.GenerateNodeKey();

var dialogueNode = new QTDialogueNode()
{
    id = id,

    // Set a character by the name of the QTCharacter asset
    characterObjectName = "Character",

    // Set the dialogue text
    text = "This is dialogue text.",

    // Create connections
    connections = new()
    {
        // Create an input connection (a connection from another node to this node)
        new NodeConnection()
        {
            inputNodeID = "other node ID",
            inputPortIndex = 0,
            outputNodeID = id,
            outputPortIndex = 0
        },

        // Create an output connection (a connection from this node to another node)
        new NodeConnection()
        {
            inputNodeID = id,
            inputPortIndex = 0,
            outputNodeID = "some other node ID",
            outputPortIndex = 0
        }
    }
};

All node fields you see in the Editor Window for each node are public. You can edit them freely.

Adding to a Graph

graph.nodes.Add(id, dialogueNode);

Removing from the Graph

graph.nodes.Remove(id);

Future Plans

This process will be simplified in the near future. See Procedural Generation.

Last updated