Creating a conversation

Letting the player converse with NPCs is a common feature of adventure games. They work by giving the player a selection of dialogue lines to choose from, and issuing a response from the NPC. In this tutorial, we'll create a two-level conversation tree about hippos. Because everyone likes hippos!

Though we'll need an NPC to talk to, this tutorial won't be about creating characters, as there are several on the subject here.

For demo purposes, you can easily create an "empty" NPC simply by attaching the NPC script to any GameObject. This script by itself won't produce any graphics or animation, but will allow us to assign a speaker other than the player in our Conversation.

We'll also need to define Menus that will display both the speech text, and the player's dialogue options. Again, this tutorial isn't about that - you can see tutorials on the Menu system here.

However, the demo game comes with it's own set of Menus that have everything we need. At the top of the Menu Manager, simply set the Asset file to Demo_MenuManager to load them into our game.

These Menus will also be present in your own Menu Manager if you opted to keep them when using the New Game Wizard.

We're now ready to start building our dialogue tree. Each "level" of this tree will be stored in a separate Conversation prefab. In the Scene Manager, select Conversation and click again to create it. Rename it Hippo base conv, as this will be our "root" Conversation prefab.

This object will store the “base level” of our conversation hierarchy, from which we can branch to other levels such as questions. Select the object and view it’s Inspector.

Let’s give the player three options to choose from - click Add new dialogue option three times.

When an option is selected, you can edit it’s properties - the top one being the label text that’s displayed in the Menu. Set the Label field for the three options to the following:

Notice the Interaction field in the list of properties. Here, we can define an a list of Actions that will run when the option is chosen. However, because we are creating a two-tier conversation, it will be easier to define these Actions in one go. Don’t worry about what that means for now - it just leave we’ll be leaving these fields blank.

Return to the Scene Manager, and create another Conversation object, this time called Hippos questions. As before, give it three dialogue options, and label them as follows:

Now that our options have been declared, we can create the Actions that both trigger them and handle their responses. In the Scene Manager, select the Cutscene prefab and create a new one called Talk about hippos. Since this will involve branching options, it will be best to edit this Cutscene within the ActionList Editor window. This window can be easily opened by clicking on the icon to the right of it’s name in the Hierarchy window.

Dock the window into a large space, and set the lone Action to Dialogue: Start conversation. Then set the Conversation field to Hippo base conv.

Remember how we left the Conversation inspector’s Interaction fields blank? That’s because we’ll be telling our game what to do when the player chooses any option right here in the Cutscene. Check Override defaults?, and you’ll see three output sockets appear - one for each option:

Let’s work our way upwards, starting with “Time to go!”. Right-click beneath the Action and choose Add new Action from the menu. Drag an arrow from the third option’s output socket to this new Action. If the other sockets have connected to it automatically, just drag their sockets into empty space:

This new Action (and any others it connects to) will dictate what happens when the player chooses the third option. Replace the Action with the following:

Because the second Action is set to Stop once it has finished running, the Cutscene will end and our Conversation will be over. Now that we’ve finished this branch, collapse both of these Actions by clicking the arrow to the top-left of their nodes, and click Auto-arrange from the top toolbar.

Now let’s build the response for our second option. Create two new Actions, set to the following:

Again, collapse the Actions and auto-arrange them:

This time, however, we want to return to our three options once these two Actions have finished. To do that, simply drag a wire from the second Action’s output socket back onto the Dialogue: Start conversation Action:

Now we’re ready for the first dialogue option, which will bring up the Hippos questions Conversation object. Create the following two Actions, stemming from the first output socket:

Collapse the Dialogue: Play speech Action, and check Override defaults? in the new Dialogue: Start conversation:

This time, we’ll work our way down. Create these Actions for the “Where do hippos live?” output socket:

Collapse, auto-arrange, and drag the second Action’s output socket back to the new Dialogue: Start conversation:

Next, create these Actions for the “What’s their latin name?” output socket:

Again, collapse, auto-arrange, and drag the second Action’s output socket to Dialogue: Start conversation:

Finally, create this single Action for the “Never mind” output socket:

We’ll want this option to result in our going back to the original conversation, so drag the output socket of this Action all the way back to our first Action. Alternatively, you can set the After running field to Skip, and Action to skip to to 0: Dialogue: Start conversation.

Our full Cutscene should look like this:

We can now call this Cutscene whenever we like in-game to trigger our branching conversation. To test it quickly, simply click Run now within it’s Inspector whenever the game is running.

We can navigate through the various options, and get appropriate responses, but it could do with some improvement. In the next tutorial, we'll make things a bit more dynamic and interesting.

Adventure Creator and this website are copyright Chris Burton, ICEBOX Studios

Go to top