Documentation

Learn how to use NodeCanvas

Download PDF Version

Dialogue Trees

DialogueTreeExampleThe above Dialogue Tree is included in the downloadable examples

With the bonus Dialogue Trees module included in NodeCanvas, you are able to create non-linear, multi-actor dialogue trees with the same familiar node editor as the rest of the NodeCanvas modules.

1 – Create the Dialogue Tree

Dialogue Trees work a bit different setup-wise than the rest of the modules, in the sense that there is no GraphOwner component needed for them to work. Instead, you just need to create a Dialogue Tree from the top Unity menu “Tools/ParadoxNotion/NodeCanvas/Create/Dialogue Tree Object”. When that is done, a new game object with the Dialogue Tree component attached will be created in your scene hierarchy.

2 – Define the Dialogue Actors

Within the inspector of the Dialogue Tree, you will need to define the different actor parameters that will be used by this Dialogue Tree. In the example bellow, there are two actors defined, those being “John” and “Doe”.

DialogueTree

You will notice that on the right side of each actor parameter, there is a DialogueActor field as well. If you want your defined actors above to also have a visual representation within the game world, you will need to add the “DialogueActor” component on the game object that represents them, and then assign that gameobject to the respective DialogueActor field.

So for example, if we have a gameobject that we would like to use for “John”, we would need to add the DialogueActor component on that gameobject and then drag&drop that gameobject in the field next to the “John” actor parameter in the Dialogue Tree inspector.

As you will see, the DialogueActor component, has only but a few self-explanatory settings relevant to the actor’s appearence in the UI.

DialogueActor

3 – Create the Nodes

All Dialogue Tree nodes have one dropdown setting in common at the top of their inspector, that being “which actor this node is for”. Within this dropdown, all previously defined actor parameters will be listed. The actor selected here is the actor that will be used for that node. In the following example, the node has been set to be used by “John”. As such, John is the one that will say “This is a dialogue text”.

DialogueNode

The Instigator

By now, you might be wondering what the “Instigator” option shown in the actor selection dropdown is. Simply put, the “Instigator” is the default actor. When starting a Dialogue Tree from code, you have the option to set it’s default actor. As such, wherever the Instigator is selected, that default actor will be used instead, which can prove to be usefull for creating reusable Dialogue Trees.

Dynamic Text through Variables

Within the “Say” or “Multiple Choice” nodes of the Dialogue Tree, you are also able to have dymamic dialogue text displayed by the use of the local dialogue tree variables, by using the variable’s name within square brackets within the text. For example, if you had a integer variable named “apples”, you can write the dialogue text like so:

  • “I have [apples] apples in my pocket”.

In game, “[apples]” will be replaced by the variable’s value ToString and for example show this instead (in case the “apples” variable is an int with a value of 3) :

  • “I have 3 apples in my pocket”.

Needless to say, this is very usefull and something to be remembered if you are after creating some dymamic dialogue trees!

4 – Add the UI

You will obviously need a UI to display the dialogue. While you are able to create your own, there already exists one which you can use to get started quickly. All you have to do, is to add the prefab named “@DialogueUGUI” in the scene and you are good to go.

Notice: For any UI to work correctly, you will also need to add the Unity Event System through “GameObject/UI/Event System” if one is not already in the scene.

5 – Start the Dialogue

Starting the dialogue in game is a matter of a simple function call. For example:

If you are working with NodeCanvas FSMs or Behaviour Trees, there also exists an ActionTask called “StartDialogue” which you can use instead of doing this in code.

Finaly, here are the various overload methods that the StartDialogue comes with:

 

 

Yes No Suggest edit
5 of 10 users found this section helpful
Suggest Edit